mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +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,
|
||||
},
|
||||
|
||||
/// 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
|
||||
///
|
||||
/// ## Resolution
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
#[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.
|
||||
///
|
||||
/// Default impl raises [`ShellError::UnsupportedOperator`].
|
||||
/// Default impl raises [`ShellError::OperatorUnsupportedType`].
|
||||
fn operation(
|
||||
&self,
|
||||
lhs_span: Span,
|
||||
|
@ -77,7 +77,13 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
|
|||
right: &Value,
|
||||
) -> Result<Value, ShellError> {
|
||||
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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use nu_protocol::{
|
||||
ast::{self, Math, Operator},
|
||||
CustomValue, ShellError, Span, Value,
|
||||
CustomValue, ShellError, Span, Type, Value,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
|
@ -108,7 +108,7 @@ impl CustomValue for CoolCustomValue {
|
|||
|
||||
fn operation(
|
||||
&self,
|
||||
_lhs_span: Span,
|
||||
lhs_span: Span,
|
||||
operator: ast::Operator,
|
||||
op_span: Span,
|
||||
right: &Value,
|
||||
|
@ -137,9 +137,12 @@ impl CustomValue for CoolCustomValue {
|
|||
})
|
||||
}
|
||||
}
|
||||
_ => Err(ShellError::UnsupportedOperator {
|
||||
operator,
|
||||
span: op_span,
|
||||
_ => Err(ShellError::OperatorUnsupportedType {
|
||||
op: Operator::Math(Math::Concatenate),
|
||||
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;
|
||||
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 uuid::Uuid;
|
||||
|
||||
pub use file_type::PolarsFileType;
|
||||
pub use nu_dataframe::{Axis, Column, NuDataFrame, NuDataFrameCustomValue};
|
||||
pub use nu_expression::{NuExpression, NuExpressionCustomValue};
|
||||
pub use nu_lazyframe::{NuLazyFrame, NuLazyFrameCustomValue};
|
||||
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_when::{NuWhen, NuWhenCustomValue, NuWhenType};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{Cacheable, PolarsPlugin};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PolarsPluginType {
|
||||
|
@ -217,13 +218,16 @@ pub trait PolarsPluginCustomValue: CustomValue {
|
|||
&self,
|
||||
_plugin: &PolarsPlugin,
|
||||
_engine: &EngineInterface,
|
||||
_lhs_span: Span,
|
||||
lhs_span: Span,
|
||||
operator: Spanned<Operator>,
|
||||
_right: Value,
|
||||
) -> Result<Value, ShellError> {
|
||||
Err(ShellError::UnsupportedOperator {
|
||||
operator: operator.item,
|
||||
span: operator.span,
|
||||
Err(ShellError::OperatorUnsupportedType {
|
||||
op: operator.item,
|
||||
unsupported: Type::Custom(self.type_name().into()),
|
||||
op_span: operator.span,
|
||||
unsupported_span: lhs_span,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue