mirror of
https://github.com/nushell/nushell
synced 2024-12-29 06:23:11 +00:00
Replace ShellError::UnsupportedOperator
with new operator errors
This commit is contained in:
parent
183956eac1
commit
000885202a
4 changed files with 30 additions and 31 deletions
|
@ -164,20 +164,6 @@ pub enum ShellError {
|
||||||
call_span: Span,
|
call_span: Span,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// This value cannot be used with this operator.
|
|
||||||
///
|
|
||||||
/// ## Resolution
|
|
||||||
///
|
|
||||||
/// Not all values, for example custom values, can be used with all operators. Either
|
|
||||||
/// implement support for the operator on this type, or convert the type to a supported one.
|
|
||||||
#[error("Unsupported operator: {operator}.")]
|
|
||||||
#[diagnostic(code(nu::shell::unsupported_operator))]
|
|
||||||
UnsupportedOperator {
|
|
||||||
operator: Operator,
|
|
||||||
#[label = "unsupported operator"]
|
|
||||||
span: Span,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// Invalid assignment left-hand side
|
/// Invalid assignment left-hand side
|
||||||
///
|
///
|
||||||
/// ## Resolution
|
/// ## Resolution
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{cmp::Ordering, fmt};
|
use std::{cmp::Ordering, fmt};
|
||||||
|
|
||||||
use crate::{ast::Operator, ShellError, Span, Value};
|
use crate::{ast::Operator, ShellError, Span, Type, Value};
|
||||||
|
|
||||||
/// Trait definition for a custom [`Value`](crate::Value) type
|
/// Trait definition for a custom [`Value`](crate::Value) type
|
||||||
#[typetag::serde(tag = "type")]
|
#[typetag::serde(tag = "type")]
|
||||||
|
@ -68,7 +68,7 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
|
||||||
///
|
///
|
||||||
/// The Operator enum is used to indicate the expected operation.
|
/// The Operator enum is used to indicate the expected operation.
|
||||||
///
|
///
|
||||||
/// Default impl raises [`ShellError::UnsupportedOperator`].
|
/// Default impl raises [`ShellError::OperatorUnsupportedType`].
|
||||||
fn operation(
|
fn operation(
|
||||||
&self,
|
&self,
|
||||||
lhs_span: Span,
|
lhs_span: Span,
|
||||||
|
@ -77,7 +77,13 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
|
||||||
right: &Value,
|
right: &Value,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let _ = (lhs_span, right);
|
let _ = (lhs_span, right);
|
||||||
Err(ShellError::UnsupportedOperator { operator, span: op })
|
Err(ShellError::OperatorUnsupportedType {
|
||||||
|
op: operator,
|
||||||
|
unsupported: Type::Custom(self.type_name().into()),
|
||||||
|
op_span: op,
|
||||||
|
unsupported_span: lhs_span,
|
||||||
|
help: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For custom values in plugins: return `true` here if you would like to be notified when all
|
/// For custom values in plugins: return `true` here if you would like to be notified when all
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{self, Math, Operator},
|
ast::{self, Math, Operator},
|
||||||
CustomValue, ShellError, Span, Value,
|
CustomValue, ShellError, Span, Type, Value,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
@ -108,7 +108,7 @@ impl CustomValue for CoolCustomValue {
|
||||||
|
|
||||||
fn operation(
|
fn operation(
|
||||||
&self,
|
&self,
|
||||||
_lhs_span: Span,
|
lhs_span: Span,
|
||||||
operator: ast::Operator,
|
operator: ast::Operator,
|
||||||
op_span: Span,
|
op_span: Span,
|
||||||
right: &Value,
|
right: &Value,
|
||||||
|
@ -137,9 +137,12 @@ impl CustomValue for CoolCustomValue {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(ShellError::UnsupportedOperator {
|
_ => Err(ShellError::OperatorUnsupportedType {
|
||||||
operator,
|
op: Operator::Math(Math::Concatenate),
|
||||||
span: op_span,
|
unsupported: Type::Custom(self.type_name().into()),
|
||||||
|
op_span,
|
||||||
|
unsupported_span: lhs_span,
|
||||||
|
help: None,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,20 +7,21 @@ mod nu_schema;
|
||||||
mod nu_when;
|
mod nu_when;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
use crate::{Cacheable, PolarsPlugin};
|
||||||
|
use nu_plugin::EngineInterface;
|
||||||
|
use nu_protocol::{
|
||||||
|
ast::Operator, CustomValue, PipelineData, ShellError, Span, Spanned, Type, Value,
|
||||||
|
};
|
||||||
use std::{cmp::Ordering, fmt};
|
use std::{cmp::Ordering, fmt};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub use file_type::PolarsFileType;
|
pub use file_type::PolarsFileType;
|
||||||
pub use nu_dataframe::{Axis, Column, NuDataFrame, NuDataFrameCustomValue};
|
pub use nu_dataframe::{Axis, Column, NuDataFrame, NuDataFrameCustomValue};
|
||||||
pub use nu_expression::{NuExpression, NuExpressionCustomValue};
|
pub use nu_expression::{NuExpression, NuExpressionCustomValue};
|
||||||
pub use nu_lazyframe::{NuLazyFrame, NuLazyFrameCustomValue};
|
pub use nu_lazyframe::{NuLazyFrame, NuLazyFrameCustomValue};
|
||||||
pub use nu_lazygroupby::{NuLazyGroupBy, NuLazyGroupByCustomValue};
|
pub use nu_lazygroupby::{NuLazyGroupBy, NuLazyGroupByCustomValue};
|
||||||
use nu_plugin::EngineInterface;
|
|
||||||
use nu_protocol::{ast::Operator, CustomValue, PipelineData, ShellError, Span, Spanned, Value};
|
|
||||||
pub use nu_schema::{str_to_dtype, NuSchema};
|
pub use nu_schema::{str_to_dtype, NuSchema};
|
||||||
pub use nu_when::{NuWhen, NuWhenCustomValue, NuWhenType};
|
pub use nu_when::{NuWhen, NuWhenCustomValue, NuWhenType};
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::{Cacheable, PolarsPlugin};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum PolarsPluginType {
|
pub enum PolarsPluginType {
|
||||||
|
@ -217,13 +218,16 @@ pub trait PolarsPluginCustomValue: CustomValue {
|
||||||
&self,
|
&self,
|
||||||
_plugin: &PolarsPlugin,
|
_plugin: &PolarsPlugin,
|
||||||
_engine: &EngineInterface,
|
_engine: &EngineInterface,
|
||||||
_lhs_span: Span,
|
lhs_span: Span,
|
||||||
operator: Spanned<Operator>,
|
operator: Spanned<Operator>,
|
||||||
_right: Value,
|
_right: Value,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
Err(ShellError::UnsupportedOperator {
|
Err(ShellError::OperatorUnsupportedType {
|
||||||
operator: operator.item,
|
op: operator.item,
|
||||||
span: operator.span,
|
unsupported: Type::Custom(self.type_name().into()),
|
||||||
|
op_span: operator.span,
|
||||||
|
unsupported_span: lhs_span,
|
||||||
|
help: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue