forked from extern/nushell
Document and critically review ShellError
variants - Ep. 3 (#8340)
Continuation of #8229 and #8326 # Description The `ShellError` enum at the moment is kind of messy. Many variants are basic tuple structs where you always have to reference the implementation with its macro invocation to know which field serves which purpose. Furthermore we have both variants that are kind of redundant or either overly broad to be useful for the user to match on or overly specific with few uses. So I set out to start fixing the lacking documentation and naming to make it feasible to critically review the individual usages and fix those. Furthermore we can decide to join or split up variants that don't seem to be fit for purpose. # Call to action **Everyone:** Feel free to add review comments if you spot inconsistent use of `ShellError` variants. # User-Facing Changes (None now, end goal more explicit and consistent error messages) # Tests + Formatting (No additional tests needed so far) # Commits (so far) - Remove `ShellError::FeatureNotEnabled` - Name fields on `SE::ExternalNotSupported` - Name field on `SE::InvalidProbability` - Name fields on `SE::NushellFailed` variants - Remove unused `SE::NushellFailedSpannedHelp` - Name field on `SE::VariableNotFoundAtRuntime` - Name fields on `SE::EnvVarNotFoundAtRuntime` - Name fields on `SE::ModuleNotFoundAtRuntime` - Remove usused `ModuleOrOverlayNotFoundAtRuntime` - Name fields on `SE::OverlayNotFoundAtRuntime` - Name field on `SE::NotFound`
This commit is contained in:
committed by
GitHub
parent
4898750fc1
commit
62575c9a4f
@ -50,11 +50,11 @@ impl Command for Alias {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Err(ShellError::NushellFailedSpanned(
|
||||
"Can't run alias directly. Unwrap it first".to_string(),
|
||||
"originates from here".to_string(),
|
||||
call.head,
|
||||
))
|
||||
Err(ShellError::NushellFailedSpanned {
|
||||
msg: "Can't run alias directly. Unwrap it first".to_string(),
|
||||
label: "originates from here".to_string(),
|
||||
span: call.head,
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -108,7 +108,7 @@ impl Stack {
|
||||
return Ok(v.clone().with_span(span));
|
||||
}
|
||||
|
||||
Err(ShellError::VariableNotFoundAtRuntime(span))
|
||||
Err(ShellError::VariableNotFoundAtRuntime { span })
|
||||
}
|
||||
|
||||
pub fn get_var_with_origin(&self, var_id: VarId, span: Span) -> Result<Value, ShellError> {
|
||||
@ -116,7 +116,7 @@ impl Stack {
|
||||
return Ok(v.clone());
|
||||
}
|
||||
|
||||
Err(ShellError::VariableNotFoundAtRuntime(span))
|
||||
Err(ShellError::VariableNotFoundAtRuntime { span })
|
||||
}
|
||||
|
||||
pub fn add_var(&mut self, var_id: VarId, value: Value) {
|
||||
@ -152,7 +152,9 @@ impl Stack {
|
||||
self.active_overlays
|
||||
.last()
|
||||
.cloned()
|
||||
.ok_or_else(|| ShellError::NushellFailed("No active overlay".into()))
|
||||
.ok_or_else(|| ShellError::NushellFailed {
|
||||
msg: "No active overlay".into(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn captures_to_stack(&self, captures: &HashMap<VarId, Value>) -> Stack {
|
||||
|
@ -587,12 +587,10 @@ impl PipelineData {
|
||||
let stderr = stderr_handler.map(|(handler, stderr_span, stderr_ctrlc)| {
|
||||
let stderr_bytes = handler
|
||||
.join()
|
||||
.map_err(|err| {
|
||||
ShellError::ExternalCommand(
|
||||
"Fail to receive external commands stderr message".to_string(),
|
||||
format!("{err:?}"),
|
||||
stderr_span,
|
||||
)
|
||||
.map_err(|err| ShellError::ExternalCommand {
|
||||
label: "Fail to receive external commands stderr message".to_string(),
|
||||
help: format!("{err:?}"),
|
||||
span: stderr_span,
|
||||
})
|
||||
.unwrap_or_default();
|
||||
RawStream::new(
|
||||
|
@ -226,15 +226,6 @@ pub enum ShellError {
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// This build of nushell implements this feature, but it has not been enabled.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Rebuild nushell with the appropriate feature enabled.
|
||||
#[error("Feature not enabled.")]
|
||||
#[diagnostic(code(nu::shell::feature_not_enabled))]
|
||||
FeatureNotEnabled(#[label = "feature not enabled"] Span),
|
||||
|
||||
/// You're trying to run an unsupported external command.
|
||||
///
|
||||
/// ## Resolution
|
||||
@ -242,8 +233,12 @@ pub enum ShellError {
|
||||
/// Make sure there's an appropriate `run-external` declaration for this external command.
|
||||
#[error("Running external commands not supported")]
|
||||
#[diagnostic(code(nu::shell::external_commands))]
|
||||
ExternalNotSupported(#[label = "external not supported"] Span),
|
||||
ExternalNotSupported {
|
||||
#[label = "external not supported"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
// TODO: consider moving to a more generic error variant for invalid values
|
||||
/// The given probability input is invalid. The probability must be between 0 and 1.
|
||||
///
|
||||
/// ## Resolution
|
||||
@ -251,7 +246,10 @@ pub enum ShellError {
|
||||
/// Make sure the probability is between 0 and 1 and try again.
|
||||
#[error("Invalid Probability.")]
|
||||
#[diagnostic(code(nu::shell::invalid_probability))]
|
||||
InvalidProbability(#[label = "invalid probability"] Span),
|
||||
InvalidProbability {
|
||||
#[label = "invalid probability: must be between 0 and 1"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// The first value in a `..` range must be compatible with the second one.
|
||||
///
|
||||
@ -272,40 +270,47 @@ pub enum ShellError {
|
||||
/// ## Resolution
|
||||
///
|
||||
/// It is very likely that this is a bug. Please file an issue at https://github.com/nushell/nushell/issues with relevant information.
|
||||
#[error("Nushell failed: {0}.")]
|
||||
#[diagnostic(code(nu::shell::nushell_failed))]
|
||||
#[error("Nushell failed: {msg}.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::nushell_failed),
|
||||
help(
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
))]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailed(String),
|
||||
NushellFailed { msg: String },
|
||||
|
||||
/// Catastrophic nushell failure. This reflects a completely unexpected or unrecoverable error.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// It is very likely that this is a bug. Please file an issue at https://github.com/nushell/nushell/issues with relevant information.
|
||||
#[error("Nushell failed: {0}.")]
|
||||
#[diagnostic(code(nu::shell::nushell_failed_spanned))]
|
||||
#[error("Nushell failed: {msg}.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::nushell_failed_spanned),
|
||||
help(
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
))]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailedSpanned(String, String, #[label = "{1}"] Span),
|
||||
NushellFailedSpanned {
|
||||
msg: String,
|
||||
label: String,
|
||||
#[label = "{label}"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// Catastrophic nushell failure. This reflects a completely unexpected or unrecoverable error.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// It is very likely that this is a bug. Please file an issue at https://github.com/nushell/nushell/issues with relevant information.
|
||||
#[error("Nushell failed: {0}.")]
|
||||
#[error("Nushell failed: {msg}.")]
|
||||
#[diagnostic(code(nu::shell::nushell_failed_help))]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailedHelp(String, #[help] String),
|
||||
|
||||
/// Catastrophic nushell failure. This reflects a completely unexpected or unrecoverable error.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// It is very likely that this is a bug. Please file an issue at https://github.com/nushell/nushell/issues with relevant information.
|
||||
#[error("Nushell failed: {0}.")]
|
||||
#[diagnostic(code(nu::shell::nushell_failed_spanned_help))]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailedSpannedHelp(String, String, #[label = "{1}"] Span, #[help] String),
|
||||
NushellFailedHelp {
|
||||
msg: String,
|
||||
#[help]
|
||||
help: String,
|
||||
},
|
||||
|
||||
/// A referenced variable was not found at runtime.
|
||||
///
|
||||
@ -314,43 +319,49 @@ pub enum ShellError {
|
||||
/// Check the variable name. Did you typo it? Did you forget to declare it? Is the casing right?
|
||||
#[error("Variable not found")]
|
||||
#[diagnostic(code(nu::shell::variable_not_found))]
|
||||
VariableNotFoundAtRuntime(#[label = "variable not found"] Span),
|
||||
VariableNotFoundAtRuntime {
|
||||
#[label = "variable not found"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// A referenced environment variable was not found at runtime.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Check the environment variable name. Did you typo it? Did you forget to declare it? Is the casing right?
|
||||
#[error("Environment variable '{0}' not found")]
|
||||
#[error("Environment variable '{envvar_name}' not found")]
|
||||
#[diagnostic(code(nu::shell::env_variable_not_found))]
|
||||
EnvVarNotFoundAtRuntime(String, #[label = "environment variable not found"] Span),
|
||||
EnvVarNotFoundAtRuntime {
|
||||
envvar_name: String,
|
||||
#[label = "environment variable not found"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// A referenced module was not found at runtime.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Check the module name. Did you typo it? Did you forget to declare it? Is the casing right?
|
||||
#[error("Module '{0}' not found")]
|
||||
#[error("Module '{mod_name}' not found")]
|
||||
#[diagnostic(code(nu::shell::module_not_found))]
|
||||
ModuleNotFoundAtRuntime(String, #[label = "module not found"] Span),
|
||||
|
||||
/// A referenced module or overlay was not found at runtime.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Check the module name. Did you typo it? Did you forget to declare it? Is the casing right?
|
||||
#[error("Module or overlay'{0}' not found")]
|
||||
#[diagnostic(code(nu::shell::module_or_overlay_not_found))]
|
||||
ModuleOrOverlayNotFoundAtRuntime(String, #[label = "not a module or overlay"] Span),
|
||||
ModuleNotFoundAtRuntime {
|
||||
mod_name: String,
|
||||
#[label = "module not found"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// A referenced overlay was not found at runtime.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Check the overlay name. Did you typo it? Did you forget to declare it? Is the casing right?
|
||||
#[error("Overlay '{0}' not found")]
|
||||
#[error("Overlay '{overlay_name}' not found")]
|
||||
#[diagnostic(code(nu::shell::overlay_not_found))]
|
||||
OverlayNotFoundAtRuntime(String, #[label = "overlay not found"] Span),
|
||||
OverlayNotFoundAtRuntime {
|
||||
overlay_name: String,
|
||||
#[label = "overlay not found"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// The given item was not found. This is a fairly generic error that depends on context.
|
||||
///
|
||||
@ -359,66 +370,82 @@ pub enum ShellError {
|
||||
/// This error is triggered in various places, and simply signals that "something" was not found. Refer to the specific error message for further details.
|
||||
#[error("Not found.")]
|
||||
#[diagnostic(code(nu::parser::not_found))]
|
||||
NotFound(#[label = "did not find anything under this name"] Span),
|
||||
NotFound {
|
||||
#[label = "did not find anything under this name"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// Failed to convert a value of one type into a different type.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Not all values can be coerced this way. Check the supported type(s) and try again.
|
||||
#[error("Can't convert to {0}.")]
|
||||
#[error("Can't convert to {to_type}.")]
|
||||
#[diagnostic(code(nu::shell::cant_convert))]
|
||||
CantConvert(
|
||||
String,
|
||||
String,
|
||||
#[label("can't convert {1} to {0}")] Span,
|
||||
#[help] Option<String>,
|
||||
),
|
||||
CantConvert {
|
||||
to_type: String,
|
||||
from_type: String,
|
||||
#[label("can't convert {from_type} to {to_type}")]
|
||||
span: Span,
|
||||
#[help]
|
||||
help: Option<String>,
|
||||
},
|
||||
|
||||
/// Failed to convert a value of one type into a different type. Includes hint for what the first value is.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Not all values can be coerced this way. Check the supported type(s) and try again.
|
||||
#[error("Can't convert {1} `{2}` to {0}.")]
|
||||
#[error("Can't convert {from_type} `{details}` to {to_type}.")]
|
||||
#[diagnostic(code(nu::shell::cant_convert_with_value))]
|
||||
CantConvertWithValue(
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
#[label("can't be converted to {0}")] Span,
|
||||
#[label("this {1} value...")] Span,
|
||||
#[help] Option<String>,
|
||||
),
|
||||
CantConvertWithValue {
|
||||
to_type: String,
|
||||
from_type: String,
|
||||
details: String,
|
||||
#[label("can't be converted to {to_type}")]
|
||||
dst_span: Span,
|
||||
#[label("this {from_type} value...")]
|
||||
src_span: Span,
|
||||
#[help]
|
||||
help: Option<String>,
|
||||
},
|
||||
|
||||
/// An environment variable cannot be represented as a string.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Not all types can be converted to environment variable values, which must be strings. Check the input type and try again.
|
||||
#[error("{0} is not representable as a string.")]
|
||||
#[error("'{envvar_name}' is not representable as a string.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::env_var_not_a_string),
|
||||
help(
|
||||
r#"The '{0}' environment variable must be a string or be convertible to a string.
|
||||
Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVERSIONS."#
|
||||
)
|
||||
)]
|
||||
EnvVarNotAString(String, #[label("value not representable as a string")] Span),
|
||||
code(nu::shell::env_var_not_a_string),
|
||||
help(
|
||||
r#"The '{envvar_name}' environment variable must be a string or be convertible to a string.
|
||||
Either make sure '{envvar_name}' is a string, or add a 'to_string' entry for it in ENV_CONVERSIONS."#
|
||||
)
|
||||
)]
|
||||
EnvVarNotAString {
|
||||
envvar_name: String,
|
||||
#[label("value not representable as a string")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// This environment variable cannot be set manually.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// This environment variable is set automatically by Nushell and cannot not be set manually.
|
||||
#[error("{0} cannot be set manually.")]
|
||||
#[error("{envvar_name} cannot be set manually.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::automatic_env_var_set_manually),
|
||||
help(
|
||||
r#"The environment variable '{0}' is set automatically by Nushell and cannot not be set manually."#
|
||||
r#"The environment variable '{envvar_name}' is set automatically by Nushell and cannot not be set manually."#
|
||||
)
|
||||
)]
|
||||
AutomaticEnvVarSetManually(String, #[label("cannot set '{0}' manually")] Span),
|
||||
AutomaticEnvVarSetManually {
|
||||
envvar_name: String,
|
||||
#[label("cannot set '{envvar_name}' manually")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// It is not possible to replace the entire environment at once
|
||||
///
|
||||
@ -429,9 +456,12 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
#[error("Cannot replace environment.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::cannot_replace_env),
|
||||
help(r#"Assigning a value to $env is not allowed."#)
|
||||
help(r#"Assigning a value to '$env' is not allowed."#)
|
||||
)]
|
||||
CannotReplaceEnv(#[label("setting $env not allowed")] Span),
|
||||
CannotReplaceEnv {
|
||||
#[label("setting '$env' not allowed")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// Division by zero is not a thing.
|
||||
///
|
||||
@ -440,7 +470,10 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Add a guard of some sort to check whether a denominator input to this division is zero, and branch off if that's the case.
|
||||
#[error("Division by zero.")]
|
||||
#[diagnostic(code(nu::shell::division_by_zero))]
|
||||
DivisionByZero(#[label("division by zero")] Span),
|
||||
DivisionByZero {
|
||||
#[label("division by zero")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// An error happened while tryin to create a range.
|
||||
///
|
||||
@ -451,28 +484,36 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check your range values to make sure they're countable and would not loop forever.
|
||||
#[error("Can't convert range to countable values")]
|
||||
#[diagnostic(code(nu::shell::range_to_countable))]
|
||||
CannotCreateRange(#[label = "can't convert to countable values"] Span),
|
||||
CannotCreateRange {
|
||||
#[label = "can't convert to countable values"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// You attempted to access an index beyond the available length of a value.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Check your lengths and try again.
|
||||
#[error("Row number too large (max: {0}).")]
|
||||
#[error("Row number too large (max: {max_idx}).")]
|
||||
#[diagnostic(code(nu::shell::access_beyond_end))]
|
||||
AccessBeyondEnd(usize, #[label = "index too large (max: {0})"] Span),
|
||||
AccessBeyondEnd {
|
||||
max_idx: usize,
|
||||
#[label = "index too large (max: {max_idx})"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// You attempted to insert data at a list position higher than the end.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// To insert data into a list, assign to the last used index + 1.
|
||||
#[error("Inserted at wrong row number (should be {0}).")]
|
||||
#[error("Inserted at wrong row number (should be {available_idx}).")]
|
||||
#[diagnostic(code(nu::shell::access_beyond_end))]
|
||||
InsertAfterNextFreeIndex(
|
||||
usize,
|
||||
#[label = "can't insert at index (the next available index is {0})"] Span,
|
||||
),
|
||||
InsertAfterNextFreeIndex {
|
||||
available_idx: usize,
|
||||
#[label = "can't insert at index (the next available index is {available_idx})"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// You attempted to access an index when it's empty.
|
||||
///
|
||||
@ -481,8 +522,12 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check your lengths and try again.
|
||||
#[error("Row number too large (empty content).")]
|
||||
#[diagnostic(code(nu::shell::access_beyond_end))]
|
||||
AccessEmptyContent(#[label = "index too large (empty content)"] Span),
|
||||
AccessEmptyContent {
|
||||
#[label = "index too large (empty content)"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
// TODO: check to be taken over by `AccessBeyondEnd`
|
||||
/// You attempted to access an index beyond the available length of a stream.
|
||||
///
|
||||
/// ## Resolution
|
||||
@ -490,7 +535,10 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check your lengths and try again.
|
||||
#[error("Row number too large.")]
|
||||
#[diagnostic(code(nu::shell::access_beyond_end_of_stream))]
|
||||
AccessBeyondEndOfStream(#[label = "index too large"] Span),
|
||||
AccessBeyondEndOfStream {
|
||||
#[label = "index too large"]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// Tried to index into a type that does not support pathed access.
|
||||
///
|
||||
@ -499,7 +547,11 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check your types. Only composite types can be pathed into.
|
||||
#[error("Data cannot be accessed with a cell path")]
|
||||
#[diagnostic(code(nu::shell::incompatible_path_access))]
|
||||
IncompatiblePathAccess(String, #[label("{0} doesn't support cell paths")] Span),
|
||||
IncompatiblePathAccess {
|
||||
type_name: String,
|
||||
#[label("{type_name} doesn't support cell paths")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// The requested column does not exist.
|
||||
///
|
||||
@ -508,11 +560,13 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check the spelling of your column name. Did you forget to rename a column somewhere?
|
||||
#[error("Cannot find column")]
|
||||
#[diagnostic(code(nu::shell::column_not_found))]
|
||||
CantFindColumn(
|
||||
String,
|
||||
#[label = "cannot find column '{0}'"] Span,
|
||||
#[label = "value originates here"] Span,
|
||||
),
|
||||
CantFindColumn {
|
||||
col_name: String,
|
||||
#[label = "cannot find column '{col_name}'"]
|
||||
span: Span,
|
||||
#[label = "value originates here"]
|
||||
src_span: Span,
|
||||
},
|
||||
|
||||
/// Attempted to insert a column into a table, but a column with that name already exists.
|
||||
///
|
||||
@ -521,11 +575,13 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Drop or rename the existing column (check `rename -h`) and try again.
|
||||
#[error("Column already exists")]
|
||||
#[diagnostic(code(nu::shell::column_already_exists))]
|
||||
ColumnAlreadyExists(
|
||||
String,
|
||||
#[label = "column '{0}' already exists"] Span,
|
||||
#[label = "value originates here"] Span,
|
||||
),
|
||||
ColumnAlreadyExists {
|
||||
col_name: String,
|
||||
#[label = "column '{col_name}' already exists"]
|
||||
span: Span,
|
||||
#[label = "value originates here"]
|
||||
src_span: Span,
|
||||
},
|
||||
|
||||
/// The given operation can only be performed on lists.
|
||||
///
|
||||
@ -534,10 +590,12 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Check the input type to this command. Are you sure it's a list?
|
||||
#[error("Not a list value")]
|
||||
#[diagnostic(code(nu::shell::not_a_list))]
|
||||
NotAList(
|
||||
#[label = "value not a list"] Span,
|
||||
#[label = "value originates here"] Span,
|
||||
),
|
||||
NotAList {
|
||||
#[label = "value not a list"]
|
||||
dst_span: Span,
|
||||
#[label = "value originates here"]
|
||||
src_span: Span,
|
||||
},
|
||||
|
||||
/// An error happened while performing an external command.
|
||||
///
|
||||
@ -545,8 +603,13 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
///
|
||||
/// This error is fairly generic. Refer to the specific error message for further details.
|
||||
#[error("External command failed")]
|
||||
#[diagnostic(code(nu::shell::external_command), help("{1}"))]
|
||||
ExternalCommand(String, String, #[label("{0}")] Span),
|
||||
#[diagnostic(code(nu::shell::external_command), help("{help}"))]
|
||||
ExternalCommand {
|
||||
label: String,
|
||||
help: String,
|
||||
#[label("{label}")]
|
||||
span: Span,
|
||||
},
|
||||
|
||||
/// An operation was attempted with an input unsupported for some reason.
|
||||
///
|
||||
|
@ -27,17 +27,17 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
|
||||
|
||||
// Follow cell path functions
|
||||
fn follow_path_int(&self, _count: usize, span: Span) -> Result<Value, ShellError> {
|
||||
Err(ShellError::IncompatiblePathAccess(
|
||||
format!("{} doesn't support path access", self.value_string()),
|
||||
Err(ShellError::IncompatiblePathAccess {
|
||||
type_name: self.value_string(),
|
||||
span,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
fn follow_path_string(&self, _column_name: String, span: Span) -> Result<Value, ShellError> {
|
||||
Err(ShellError::IncompatiblePathAccess(
|
||||
format!("{} doesn't support path access", self.value_string()),
|
||||
Err(ShellError::IncompatiblePathAccess {
|
||||
type_name: self.value_string(),
|
||||
span,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
// ordering with other value
|
||||
|
@ -4,12 +4,12 @@ impl Value {
|
||||
pub fn as_f64(&self) -> Result<f64, ShellError> {
|
||||
match self {
|
||||
Value::Float { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"f64".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "f64".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,12 +18,12 @@ impl Value {
|
||||
Value::Int { val, .. } => Ok(*val),
|
||||
Value::Filesize { val, .. } => Ok(*val),
|
||||
Value::Duration { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"i64".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "i64".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ impl FromValue for Spanned<i64> {
|
||||
span: *span,
|
||||
}),
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "integer".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,12 +51,12 @@ impl FromValue for i64 {
|
||||
Value::Filesize { val, .. } => Ok(*val),
|
||||
Value::Duration { val, .. } => Ok(*val),
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "integer".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,12 +73,12 @@ impl FromValue for Spanned<f64> {
|
||||
span: *span,
|
||||
}),
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"float".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "float".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,12 +88,12 @@ impl FromValue for f64 {
|
||||
match v {
|
||||
Value::Float { val, .. } => Ok(*val),
|
||||
Value::Int { val, .. } => Ok(*val as f64),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"float".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "float".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,12 +132,12 @@ impl FromValue for Spanned<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"non-negative integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "non-negative integer".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,12 +167,12 @@ impl FromValue for usize {
|
||||
}
|
||||
}
|
||||
|
||||
v => Err(ShellError::CantConvert(
|
||||
"non-negative integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "non-negative integer".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,12 +183,12 @@ impl FromValue for String {
|
||||
match v {
|
||||
Value::CellPath { val, .. } => Ok(val.into_string()),
|
||||
Value::String { val, .. } => Ok(val.clone()),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -200,12 +200,12 @@ impl FromValue for Spanned<String> {
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::String { val, .. } => val.clone(),
|
||||
v => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
))
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
},
|
||||
span: v.span()?,
|
||||
@ -221,20 +221,20 @@ impl FromValue for Vec<String> {
|
||||
.iter()
|
||||
.map(|val| match val {
|
||||
Value::String { val, .. } => Ok(val.clone()),
|
||||
c => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
c.get_type().to_string(),
|
||||
c.span()?,
|
||||
None,
|
||||
)),
|
||||
c => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: c.get_type().to_string(),
|
||||
span: c.span()?,
|
||||
help: None,
|
||||
}),
|
||||
})
|
||||
.collect::<Result<Vec<String>, ShellError>>(),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,20 +250,20 @@ impl FromValue for Vec<Spanned<String>> {
|
||||
item: val.clone(),
|
||||
span: *span,
|
||||
}),
|
||||
c => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
c.get_type().to_string(),
|
||||
c.span()?,
|
||||
None,
|
||||
)),
|
||||
c => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: c.get_type().to_string(),
|
||||
span: c.span()?,
|
||||
help: None,
|
||||
}),
|
||||
})
|
||||
.collect::<Result<Vec<Spanned<String>>, ShellError>>(),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -275,20 +275,20 @@ impl FromValue for Vec<bool> {
|
||||
.iter()
|
||||
.map(|val| match val {
|
||||
Value::Bool { val, .. } => Ok(*val),
|
||||
c => Err(ShellError::CantConvert(
|
||||
"bool".into(),
|
||||
c.get_type().to_string(),
|
||||
c.span()?,
|
||||
None,
|
||||
)),
|
||||
c => Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: c.get_type().to_string(),
|
||||
span: c.span()?,
|
||||
help: None,
|
||||
}),
|
||||
})
|
||||
.collect::<Result<Vec<bool>, ShellError>>(),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"bool".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,12 +316,12 @@ impl FromValue for CellPath {
|
||||
})
|
||||
}
|
||||
}
|
||||
x => Err(ShellError::CantConvert(
|
||||
"cell path".into(),
|
||||
x.get_type().to_string(),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "cell path".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -330,12 +330,12 @@ impl FromValue for bool {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Bool { val, .. } => Ok(*val),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"bool".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,12 +347,12 @@ impl FromValue for Spanned<bool> {
|
||||
item: *val,
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"bool".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -361,12 +361,12 @@ impl FromValue for DateTime<FixedOffset> {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Date { val, .. } => Ok(*val),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"date".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "date".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -378,12 +378,12 @@ impl FromValue for Spanned<DateTime<FixedOffset>> {
|
||||
item: *val,
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"date".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "date".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -392,12 +392,12 @@ impl FromValue for Range {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Range { val, .. } => Ok((**val).clone()),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "range".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -409,12 +409,12 @@ impl FromValue for Spanned<Range> {
|
||||
item: (**val).clone(),
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "range".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,12 +424,12 @@ impl FromValue for Vec<u8> {
|
||||
match v {
|
||||
Value::Binary { val, .. } => Ok(val.clone()),
|
||||
Value::String { val, .. } => Ok(val.bytes().collect()),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"binary data".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "binary data".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -445,12 +445,12 @@ impl FromValue for Spanned<Vec<u8>> {
|
||||
item: val.bytes().collect(),
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"binary data".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "binary data".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -463,12 +463,12 @@ impl FromValue for Spanned<PathBuf> {
|
||||
.map_err(|err| ShellError::FileNotFoundCustom(err.to_string(), *span))?,
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "range".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -478,12 +478,12 @@ impl FromValue for Vec<Value> {
|
||||
// FIXME: we may want to fail a little nicer here
|
||||
match v {
|
||||
Value::List { vals, .. } => Ok(vals.clone()),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"Vector of values".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Vector of values".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -493,12 +493,12 @@ impl FromValue for (Vec<String>, Vec<Value>) {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Record { cols, vals, .. } => Ok((cols.clone(), vals.clone())),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"Record".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Record".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -514,12 +514,12 @@ impl FromValue for Closure {
|
||||
block_id: *val,
|
||||
captures: HashMap::new(),
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"Closure".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Closure".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -528,12 +528,12 @@ impl FromValue for Block {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
Value::Block { val, .. } => Ok(Block { block_id: *val }),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"Block".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Block".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -552,12 +552,12 @@ impl FromValue for Spanned<Closure> {
|
||||
},
|
||||
span: *span,
|
||||
}),
|
||||
v => Err(ShellError::CantConvert(
|
||||
"Closure".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
v => Err(ShellError::CantConvert {
|
||||
to_type: "Closure".into(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,21 +197,21 @@ impl Value {
|
||||
Value::Binary { val, .. } => Ok(match std::str::from_utf8(val) {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(_) => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"binary".into(),
|
||||
self.span()?,
|
||||
None,
|
||||
));
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: "binary".into(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
}),
|
||||
Value::Date { val, .. } => Ok(val.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,32 +227,32 @@ impl Value {
|
||||
span: *span,
|
||||
},
|
||||
Err(_) => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"binary".into(),
|
||||
self.span()?,
|
||||
None,
|
||||
))
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: "binary".into(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
}),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_path(&self) -> Result<PathBuf, ShellError> {
|
||||
match self {
|
||||
Value::String { val, .. } => Ok(PathBuf::from(val)),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"path".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "path".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,12 +260,12 @@ impl Value {
|
||||
match self {
|
||||
Value::Block { val, .. } => Ok(*val),
|
||||
Value::Closure { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"block".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "block".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,48 +273,48 @@ impl Value {
|
||||
match self {
|
||||
Value::Binary { val, .. } => Ok(val),
|
||||
Value::String { val, .. } => Ok(val.as_bytes()),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"binary".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "binary".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_record(&self) -> Result<(&[String], &[Value]), ShellError> {
|
||||
match self {
|
||||
Value::Record { cols, vals, .. } => Ok((cols, vals)),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"record".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "record".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_list(&self) -> Result<&[Value], ShellError> {
|
||||
match self {
|
||||
Value::List { vals, .. } => Ok(vals),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"list".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "list".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_bool(&self) -> Result<bool, ShellError> {
|
||||
match self {
|
||||
Value::Bool { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"boolean".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "boolean".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,24 +322,24 @@ impl Value {
|
||||
match self {
|
||||
Value::Float { val, .. } => Ok(*val),
|
||||
Value::Int { val, .. } => Ok(*val as f64),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"float".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "float".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_integer(&self) -> Result<i64, ShellError> {
|
||||
match self {
|
||||
Value::Int { val, .. } => Ok(*val),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"integer".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "integer".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: self.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -722,12 +722,15 @@ impl Value {
|
||||
current = item.clone();
|
||||
} else if val.is_empty() {
|
||||
err_or_null!(
|
||||
ShellError::AccessEmptyContent(*origin_span),
|
||||
ShellError::AccessEmptyContent { span: *origin_span },
|
||||
*origin_span
|
||||
)
|
||||
} else {
|
||||
err_or_null!(
|
||||
ShellError::AccessBeyondEnd(val.len() - 1, *origin_span),
|
||||
ShellError::AccessBeyondEnd {
|
||||
max_idx: val.len() - 1,
|
||||
span: *origin_span
|
||||
},
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -737,12 +740,15 @@ impl Value {
|
||||
current = Value::int(*item as i64, *origin_span);
|
||||
} else if val.is_empty() {
|
||||
err_or_null!(
|
||||
ShellError::AccessEmptyContent(*origin_span),
|
||||
ShellError::AccessEmptyContent { span: *origin_span },
|
||||
*origin_span
|
||||
)
|
||||
} else {
|
||||
err_or_null!(
|
||||
ShellError::AccessBeyondEnd(val.len() - 1, *origin_span),
|
||||
ShellError::AccessBeyondEnd {
|
||||
max_idx: val.len() - 1,
|
||||
span: *origin_span
|
||||
},
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -752,7 +758,7 @@ impl Value {
|
||||
current = item.clone();
|
||||
} else {
|
||||
err_or_null!(
|
||||
ShellError::AccessBeyondEndOfStream(*origin_span),
|
||||
ShellError::AccessBeyondEndOfStream { span: *origin_span },
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -770,10 +776,10 @@ impl Value {
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
x => {
|
||||
err_or_null!(
|
||||
ShellError::IncompatiblePathAccess(
|
||||
format!("{}", x.get_type()),
|
||||
*origin_span,
|
||||
),
|
||||
ShellError::IncompatiblePathAccess {
|
||||
type_name: format!("{}", x.get_type()),
|
||||
span: *origin_span
|
||||
},
|
||||
*origin_span
|
||||
)
|
||||
}
|
||||
@ -806,11 +812,11 @@ impl Value {
|
||||
}
|
||||
}
|
||||
err_or_null!(
|
||||
ShellError::CantFindColumn(
|
||||
column_name.to_string(),
|
||||
*origin_span,
|
||||
span,
|
||||
),
|
||||
ShellError::CantFindColumn {
|
||||
col_name: column_name.to_string(),
|
||||
span: *origin_span,
|
||||
src_span: span
|
||||
},
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -830,11 +836,11 @@ impl Value {
|
||||
}
|
||||
}
|
||||
err_or_null!(
|
||||
ShellError::CantFindColumn(
|
||||
column_name.to_string(),
|
||||
*origin_span,
|
||||
*span,
|
||||
),
|
||||
ShellError::CantFindColumn {
|
||||
col_name: column_name.to_string(),
|
||||
span: *origin_span,
|
||||
src_span: *span
|
||||
},
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -874,13 +880,11 @@ impl Value {
|
||||
Value::nothing(*origin_span)
|
||||
} else {
|
||||
Value::Error {
|
||||
error: ShellError::CantFindColumn(
|
||||
column_name.to_string(),
|
||||
*origin_span,
|
||||
// Get the exact span of the value, falling back to
|
||||
// the list's span if it's a Value::Empty
|
||||
val.span().unwrap_or(*span),
|
||||
),
|
||||
error: ShellError::CantFindColumn {
|
||||
col_name: column_name.to_string(),
|
||||
span: *origin_span,
|
||||
src_span: val.span().unwrap_or(*span),
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -890,13 +894,11 @@ impl Value {
|
||||
Value::nothing(*origin_span)
|
||||
} else {
|
||||
Value::Error {
|
||||
error: ShellError::CantFindColumn(
|
||||
column_name.to_string(),
|
||||
*origin_span,
|
||||
// Get the exact span of the value, falling back to
|
||||
// the list's span if it's a Value::Empty
|
||||
val.span().unwrap_or(*span),
|
||||
),
|
||||
error: ShellError::CantFindColumn {
|
||||
col_name: column_name.to_string(),
|
||||
span: *origin_span,
|
||||
src_span: val.span().unwrap_or(*span),
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -908,11 +910,11 @@ impl Value {
|
||||
};
|
||||
} else {
|
||||
err_or_null!(
|
||||
ShellError::CantFindColumn(
|
||||
column_name.to_string(),
|
||||
*origin_span,
|
||||
*span,
|
||||
),
|
||||
ShellError::CantFindColumn {
|
||||
col_name: column_name.to_string(),
|
||||
span: *origin_span,
|
||||
src_span: *span
|
||||
},
|
||||
*origin_span
|
||||
);
|
||||
}
|
||||
@ -923,10 +925,10 @@ impl Value {
|
||||
Value::Error { error } => err_or_null!(error.to_owned(), *origin_span),
|
||||
x => {
|
||||
err_or_null!(
|
||||
ShellError::IncompatiblePathAccess(
|
||||
format!("{}", x.get_type()),
|
||||
*origin_span,
|
||||
),
|
||||
ShellError::IncompatiblePathAccess {
|
||||
type_name: format!("{}", x.get_type()),
|
||||
span: *origin_span
|
||||
},
|
||||
*origin_span
|
||||
)
|
||||
}
|
||||
@ -1005,11 +1007,11 @@ impl Value {
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1042,11 +1044,11 @@ impl Value {
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
},
|
||||
PathMember::Int { val: row_num, span } => match self {
|
||||
@ -1058,11 +1060,19 @@ impl Value {
|
||||
// Otherwise, it's prohibited.
|
||||
vals.push(new_val);
|
||||
} else {
|
||||
return Err(ShellError::InsertAfterNextFreeIndex(vals.len(), *span));
|
||||
return Err(ShellError::InsertAfterNextFreeIndex {
|
||||
available_idx: vals.len(),
|
||||
span: *span,
|
||||
});
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => return Err(ShellError::NotAList(*span, v.span()?)),
|
||||
v => {
|
||||
return Err(ShellError::NotAList {
|
||||
dst_span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
None => {
|
||||
@ -1118,20 +1128,20 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1152,20 +1162,20 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
},
|
||||
PathMember::Int { val: row_num, span } => match self {
|
||||
@ -1173,13 +1183,21 @@ impl Value {
|
||||
if let Some(v) = vals.get_mut(*row_num) {
|
||||
v.update_data_at_cell_path(&cell_path[1..], new_val)?
|
||||
} else if vals.is_empty() {
|
||||
return Err(ShellError::AccessEmptyContent(*span));
|
||||
return Err(ShellError::AccessEmptyContent { span: *span });
|
||||
} else {
|
||||
return Err(ShellError::AccessBeyondEnd(vals.len() - 1, *span));
|
||||
return Err(ShellError::AccessBeyondEnd {
|
||||
max_idx: vals.len() - 1,
|
||||
span: *span,
|
||||
});
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(error.to_owned()),
|
||||
v => return Err(ShellError::NotAList(*span, v.span()?)),
|
||||
v => {
|
||||
return Err(ShellError::NotAList {
|
||||
dst_span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
None => {
|
||||
@ -1216,19 +1234,19 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1248,19 +1266,19 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
v => Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
)),
|
||||
v => Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
}),
|
||||
},
|
||||
PathMember::Int { val: row_num, span } => match self {
|
||||
Value::List { vals, .. } => {
|
||||
@ -1268,12 +1286,18 @@ impl Value {
|
||||
vals.remove(*row_num);
|
||||
Ok(())
|
||||
} else if vals.is_empty() {
|
||||
Err(ShellError::AccessEmptyContent(*span))
|
||||
Err(ShellError::AccessEmptyContent { span: *span })
|
||||
} else {
|
||||
Err(ShellError::AccessBeyondEnd(vals.len() - 1, *span))
|
||||
Err(ShellError::AccessBeyondEnd {
|
||||
max_idx: vals.len() - 1,
|
||||
span: *span,
|
||||
})
|
||||
}
|
||||
}
|
||||
v => Err(ShellError::NotAList(*span, v.span()?)),
|
||||
v => Err(ShellError::NotAList {
|
||||
dst_span: *span,
|
||||
src_span: v.span()?,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1300,19 +1324,19 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
v => {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
))
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1333,31 +1357,37 @@ impl Value {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
v => Err(ShellError::CantFindColumn(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
v.span()?,
|
||||
)),
|
||||
v => Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: v.span()?,
|
||||
}),
|
||||
},
|
||||
PathMember::Int { val: row_num, span } => match self {
|
||||
Value::List { vals, .. } => {
|
||||
if let Some(v) = vals.get_mut(*row_num) {
|
||||
v.remove_data_at_cell_path(&cell_path[1..])
|
||||
} else if vals.is_empty() {
|
||||
Err(ShellError::AccessEmptyContent(*span))
|
||||
Err(ShellError::AccessEmptyContent { span: *span })
|
||||
} else {
|
||||
Err(ShellError::AccessBeyondEnd(vals.len() - 1, *span))
|
||||
Err(ShellError::AccessBeyondEnd {
|
||||
max_idx: vals.len() - 1,
|
||||
span: *span,
|
||||
})
|
||||
}
|
||||
}
|
||||
v => Err(ShellError::NotAList(*span, v.span()?)),
|
||||
v => Err(ShellError::NotAList {
|
||||
dst_span: *span,
|
||||
src_span: v.span()?,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1387,11 +1417,11 @@ impl Value {
|
||||
for col in cols.iter().zip(vals.iter_mut()) {
|
||||
if col.0 == col_name {
|
||||
if cell_path.len() == 1 {
|
||||
return Err(ShellError::ColumnAlreadyExists(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::ColumnAlreadyExists {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
} else {
|
||||
return col.1.insert_data_at_cell_path(
|
||||
&cell_path[1..],
|
||||
@ -1426,11 +1456,11 @@ impl Value {
|
||||
for col in cols.iter().zip(vals.iter_mut()) {
|
||||
if col.0 == col_name {
|
||||
if cell_path.len() == 1 {
|
||||
return Err(ShellError::ColumnAlreadyExists(
|
||||
col_name.to_string(),
|
||||
*span,
|
||||
*v_span,
|
||||
));
|
||||
return Err(ShellError::ColumnAlreadyExists {
|
||||
col_name: col_name.to_string(),
|
||||
span: *span,
|
||||
src_span: *v_span,
|
||||
});
|
||||
} else {
|
||||
return col.1.insert_data_at_cell_path(
|
||||
&cell_path[1..],
|
||||
@ -1462,10 +1492,18 @@ impl Value {
|
||||
// Otherwise, it's prohibited.
|
||||
vals.push(new_val);
|
||||
} else {
|
||||
return Err(ShellError::InsertAfterNextFreeIndex(vals.len(), *span));
|
||||
return Err(ShellError::InsertAfterNextFreeIndex {
|
||||
available_idx: vals.len(),
|
||||
span: *span,
|
||||
});
|
||||
}
|
||||
}
|
||||
v => return Err(ShellError::NotAList(*span, v.span()?)),
|
||||
v => {
|
||||
return Err(ShellError::NotAList {
|
||||
dst_span: *span,
|
||||
src_span: v.span()?,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
None => {
|
||||
@ -2307,7 +2345,7 @@ impl Value {
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2317,7 +2355,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2327,7 +2365,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2337,7 +2375,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Filesize { val: rhs, .. }) => {
|
||||
@ -2354,7 +2392,7 @@ impl Value {
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2364,7 +2402,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2374,7 +2412,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
@ -2391,7 +2429,7 @@ impl Value {
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2401,7 +2439,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2411,7 +2449,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::CustomValue { val: lhs, span }, rhs) => {
|
||||
@ -2439,7 +2477,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2451,7 +2489,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2463,7 +2501,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2475,7 +2513,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Filesize { val: rhs, .. }) => {
|
||||
@ -2487,7 +2525,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2499,7 +2537,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2511,7 +2549,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
@ -2523,7 +2561,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -2535,7 +2573,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -2547,7 +2585,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::CustomValue { val: lhs, span }, rhs) => {
|
||||
@ -3082,7 +3120,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -3092,7 +3130,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
@ -3102,7 +3140,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
|
||||
@ -3112,7 +3150,7 @@ impl Value {
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::CustomValue { val: lhs, span }, rhs) => {
|
||||
|
@ -68,7 +68,7 @@ impl Range {
|
||||
incr.eq(expr_span, &zero, expr_span),
|
||||
Ok(Value::Bool { val: true, .. })
|
||||
) {
|
||||
return Err(ShellError::CannotCreateRange(expr_span));
|
||||
return Err(ShellError::CannotCreateRange { span: expr_span });
|
||||
}
|
||||
|
||||
// If to > from, then incr > 0, otherwise we iterate forever
|
||||
@ -76,7 +76,7 @@ impl Range {
|
||||
to.gt(operator.span, &from, expr_span)?,
|
||||
incr.gt(operator.next_op_span, &zero, expr_span)?,
|
||||
) {
|
||||
return Err(ShellError::CannotCreateRange(expr_span));
|
||||
return Err(ShellError::CannotCreateRange { span: expr_span });
|
||||
}
|
||||
|
||||
// If to < from, then incr < 0, otherwise we iterate forever
|
||||
@ -84,7 +84,7 @@ impl Range {
|
||||
to.lt(operator.span, &from, expr_span)?,
|
||||
incr.lt(operator.next_op_span, &zero, expr_span)?,
|
||||
) {
|
||||
return Err(ShellError::CannotCreateRange(expr_span));
|
||||
return Err(ShellError::CannotCreateRange { span: expr_span });
|
||||
}
|
||||
|
||||
Ok(Range {
|
||||
@ -218,7 +218,7 @@ impl Iterator for RangeIterator {
|
||||
} else {
|
||||
self.done = true;
|
||||
return Some(Value::Error {
|
||||
error: ShellError::CannotCreateRange(self.span),
|
||||
error: ShellError::CannotCreateRange { span: self.span },
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user