mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Spanned Value step 1: span all value cases (#10042)
# Description This doesn't really do much that the user could see, but it helps get us ready to do the steps of the refactor to split the span off of Value, so that values can be spanless. This allows us to have top-level values that can hold both a Value and a Span, without requiring that all values have them. We expect to see significant memory reduction by removing so many unnecessary spans from values. For example, a table of 100,000 rows and 5 columns would have a savings of ~8megs in just spans that are almost always duplicated. # User-Facing Changes Nothing yet # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
8da27a1a09
commit
1e3e034021
@ -84,7 +84,7 @@ impl Command for Commandline {
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "int".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span: cmd.span()?,
|
||||
span: cmd.span(),
|
||||
help: Some(format!(
|
||||
r#"string "{cmd_str}" does not represent a valid integer"#
|
||||
)),
|
||||
|
@ -185,7 +185,7 @@ pub(crate) fn print_table_or_error(
|
||||
// Change the engine_state config to use the passed in configuration
|
||||
engine_state.set_config(config);
|
||||
|
||||
if let PipelineData::Value(Value::Error { error }, ..) = &pipeline_data {
|
||||
if let PipelineData::Value(Value::Error { error, .. }, ..) = &pipeline_data {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &**error);
|
||||
std::process::exit(1);
|
||||
@ -232,7 +232,7 @@ pub(crate) fn print_table_or_error(
|
||||
|
||||
fn print_or_exit(pipeline_data: PipelineData, engine_state: &mut EngineState, config: &Config) {
|
||||
for item in pipeline_data {
|
||||
if let Value::Error { error } = item {
|
||||
if let Value::Error { error, .. } = item {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
report_error(&working_set, &*error);
|
||||
|
@ -55,6 +55,7 @@ impl Command for NuHighlight {
|
||||
}
|
||||
Err(err) => Value::Error {
|
||||
error: Box::new(err),
|
||||
span: head,
|
||||
},
|
||||
},
|
||||
ctrlc,
|
||||
|
@ -141,14 +141,14 @@ fn add_menu(
|
||||
_ => Err(ShellError::UnsupportedConfigValue(
|
||||
"columnar, list or description".to_string(),
|
||||
menu.menu_type.into_abbreviated_string(config),
|
||||
menu.menu_type.span()?,
|
||||
menu.menu_type.span(),
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::UnsupportedConfigValue(
|
||||
"only record type".to_string(),
|
||||
menu.menu_type.into_abbreviated_string(config),
|
||||
menu.menu_type.span()?,
|
||||
menu.menu_type.span(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -264,7 +264,7 @@ pub(crate) fn add_columnar_menu(
|
||||
_ => Err(ShellError::UnsupportedConfigValue(
|
||||
"block or omitted value".to_string(),
|
||||
menu.source.into_abbreviated_string(config),
|
||||
menu.source.span()?,
|
||||
menu.source.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ pub(crate) fn add_list_menu(
|
||||
_ => Err(ShellError::UnsupportedConfigValue(
|
||||
"block or omitted value".to_string(),
|
||||
menu.source.into_abbreviated_string(config),
|
||||
menu.source.span()?,
|
||||
menu.source.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -466,7 +466,7 @@ pub(crate) fn add_description_menu(
|
||||
_ => Err(ShellError::UnsupportedConfigValue(
|
||||
"closure or omitted value".to_string(),
|
||||
menu.source.into_abbreviated_string(config),
|
||||
menu.source.span()?,
|
||||
menu.source.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -603,7 +603,7 @@ fn add_keybinding(
|
||||
v => Err(ShellError::UnsupportedConfigValue(
|
||||
"string or list of strings".to_string(),
|
||||
v.into_abbreviated_string(config),
|
||||
v.span()?,
|
||||
v.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -633,7 +633,7 @@ fn add_parsed_keybinding(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"CONTROL, SHIFT, ALT or NONE".to_string(),
|
||||
keybinding.modifier.into_abbreviated_string(config),
|
||||
keybinding.modifier.span()?,
|
||||
keybinding.modifier.span(),
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -657,7 +657,7 @@ fn add_parsed_keybinding(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"char_<CHAR: unicode codepoint>".to_string(),
|
||||
c.to_string(),
|
||||
keybinding.keycode.span()?,
|
||||
keybinding.keycode.span(),
|
||||
));
|
||||
};
|
||||
|
||||
@ -684,7 +684,7 @@ fn add_parsed_keybinding(
|
||||
.ok_or(ShellError::UnsupportedConfigValue(
|
||||
"(f1|f2|...|f20)".to_string(),
|
||||
format!("unknown function key: {c}"),
|
||||
keybinding.keycode.span()?,
|
||||
keybinding.keycode.span(),
|
||||
))?;
|
||||
KeyCode::F(fn_num)
|
||||
}
|
||||
@ -694,7 +694,7 @@ fn add_parsed_keybinding(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"crossterm KeyCode".to_string(),
|
||||
keybinding.keycode.into_abbreviated_string(config),
|
||||
keybinding.keycode.span()?,
|
||||
keybinding.keycode.span(),
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -751,7 +751,7 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
|
||||
None => Err(ShellError::UnsupportedConfigValue(
|
||||
"List containing valid events".to_string(),
|
||||
"Nothing value (null)".to_string(),
|
||||
value.span()?,
|
||||
value.span(),
|
||||
)),
|
||||
Some(event) => Ok(event),
|
||||
},
|
||||
@ -764,7 +764,7 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
|
||||
v => Err(ShellError::UnsupportedConfigValue(
|
||||
"list of events".to_string(),
|
||||
v.into_abbreviated_string(config),
|
||||
v.span()?,
|
||||
v.span(),
|
||||
)),
|
||||
},
|
||||
},
|
||||
@ -776,7 +776,7 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
|
||||
None => Err(ShellError::UnsupportedConfigValue(
|
||||
"List containing valid events".to_string(),
|
||||
"Nothing value (null)".to_string(),
|
||||
value.span()?,
|
||||
value.span(),
|
||||
)),
|
||||
Some(event) => Ok(event),
|
||||
},
|
||||
@ -790,7 +790,7 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
|
||||
v => Err(ShellError::UnsupportedConfigValue(
|
||||
"record or list of records, null to unbind key".to_string(),
|
||||
v.into_abbreviated_string(config),
|
||||
v.span()?,
|
||||
v.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -965,7 +965,7 @@ fn edit_from_record(
|
||||
}
|
||||
|
||||
fn extract_char(value: &Value, config: &Config) -> Result<char, ShellError> {
|
||||
let span = value.span()?;
|
||||
let span = value.span();
|
||||
value
|
||||
.into_string("", config)
|
||||
.chars()
|
||||
|
@ -78,6 +78,7 @@ where
|
||||
if let Err(error) = r {
|
||||
return Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ fn command_eager(
|
||||
df: NuDataFrame,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let mask_value: Value = call.req(engine_state, stack, 0)?;
|
||||
let mask_span = mask_value.span()?;
|
||||
let mask_span = mask_value.span();
|
||||
|
||||
if NuExpression::can_downcast(&mask_value) {
|
||||
let expression = NuExpression::try_from_value(mask_value)?;
|
||||
|
@ -160,7 +160,7 @@ fn command_lazy(
|
||||
let value: Value = call.req(engine_state, stack, 1)?;
|
||||
return Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "New name list has different size to column list".into(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -134,16 +134,17 @@ fn command(
|
||||
))
|
||||
}
|
||||
}
|
||||
_ => match value.span() {
|
||||
Ok(span) => Err(ShellError::GenericError(
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
_ => {
|
||||
let span = value.span();
|
||||
Err(ShellError::GenericError(
|
||||
"Incorrect value for quantile".to_string(),
|
||||
"value should be a float".to_string(),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
Err(e) => Err(e),
|
||||
},
|
||||
))
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<f64>, ShellError>>()
|
||||
});
|
||||
|
@ -93,7 +93,7 @@ fn command(
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let index_value: Value = call.req(engine_state, stack, 0)?;
|
||||
let index_span = index_value.span()?;
|
||||
let index_span = index_value.span();
|
||||
let index = NuDataFrame::try_from_value(index_value)?.as_series(index_span)?;
|
||||
|
||||
let casted = match index.dtype() {
|
||||
|
@ -114,7 +114,7 @@ impl Command for WithColumn {
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
@ -128,7 +128,7 @@ fn command_eager(
|
||||
mut df: NuDataFrame,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let new_column: Value = call.req(engine_state, stack, 0)?;
|
||||
let column_span = new_column.span()?;
|
||||
let column_span = new_column.span();
|
||||
|
||||
if NuExpression::can_downcast(&new_column) {
|
||||
let vals: Vec<Value> = call.rest(engine_state, stack, 0)?;
|
||||
|
@ -93,7 +93,7 @@ impl Command for LazyFillNA {
|
||||
None,
|
||||
))
|
||||
} else {
|
||||
let val_span = value.span()?;
|
||||
let val_span = value.span();
|
||||
let frame = NuDataFrame::try_from_value(value)?;
|
||||
let columns = frame.columns(val_span)?;
|
||||
let dataframe = columns
|
||||
|
@ -126,7 +126,7 @@ impl Command for ToLazyGroupBy {
|
||||
let value: Value = call.req(engine_state, stack, 0)?;
|
||||
return Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "Expected only Col expressions".into(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ impl Command for LazyJoin {
|
||||
let right_on: Value = call.req(engine_state, stack, 2)?;
|
||||
return Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "The right column list has a different size to the left column list".into(),
|
||||
span: right_on.span()?,
|
||||
span: right_on.span(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ impl Command for LazyJoin {
|
||||
let value: Value = call.req(engine_state, stack, *index)?;
|
||||
return Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "Expected only a string, col expressions or list of strings".into(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl Command for LazySortBy {
|
||||
let span = call
|
||||
.get_flag::<Value>(engine_state, stack, "reverse")?
|
||||
.expect("already checked and it exists")
|
||||
.span()?;
|
||||
.span();
|
||||
return Err(ShellError::GenericError(
|
||||
"Incorrect list size".into(),
|
||||
"Size doesn't match expression list".into(),
|
||||
|
@ -82,7 +82,7 @@ fn command(
|
||||
let indices_value: Value = call
|
||||
.get_flag(engine_state, stack, "indices")?
|
||||
.expect("required named value");
|
||||
let indices_span = indices_value.span()?;
|
||||
let indices_span = indices_value.span();
|
||||
let indices = NuDataFrame::try_from_value(indices_value)?.as_series(indices_span)?;
|
||||
|
||||
let casted = match indices.dtype() {
|
||||
@ -204,7 +204,7 @@ fn command(
|
||||
"this value cannot be set in a series of type '{}'",
|
||||
series.dtype()
|
||||
),
|
||||
Some(value.span()?),
|
||||
Some(value.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
|
@ -74,7 +74,7 @@ fn command(
|
||||
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
|
||||
|
||||
let other_value: Value = call.req(engine_state, stack, 0)?;
|
||||
let other_span = other_value.span()?;
|
||||
let other_span = other_value.span();
|
||||
let other_df = NuDataFrame::try_from_value(other_value)?;
|
||||
let other = other_df.as_series(other_span)?;
|
||||
|
||||
|
@ -81,7 +81,7 @@ fn command(
|
||||
let mask_value: Value = call
|
||||
.get_flag(engine_state, stack, "mask")?
|
||||
.expect("required named value");
|
||||
let mask_span = mask_value.span()?;
|
||||
let mask_span = mask_value.span();
|
||||
let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?;
|
||||
|
||||
let bool_mask = match mask.dtype() {
|
||||
@ -185,7 +185,7 @@ fn command(
|
||||
"this value cannot be set in a series of type '{}'",
|
||||
series.dtype()
|
||||
),
|
||||
Some(value.span()?),
|
||||
Some(value.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
|
@ -74,7 +74,7 @@ fn command(
|
||||
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
|
||||
|
||||
let other: Value = call.req(engine_state, stack, 0)?;
|
||||
let other_span = other.span()?;
|
||||
let other_span = other.span();
|
||||
let other_df = NuDataFrame::try_from_value(other)?;
|
||||
|
||||
let other_series = other_df.as_series(other_span)?;
|
||||
|
@ -9,7 +9,7 @@ pub fn extract_strings(value: Value) -> Result<Vec<String>, ShellError> {
|
||||
(Err(_), Ok(cols)) => Ok(cols),
|
||||
_ => Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "Expected a string or list of strings".into(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub(super) fn between_dataframes(
|
||||
right: &Value,
|
||||
rhs: &NuDataFrame,
|
||||
) -> Result<Value, ShellError> {
|
||||
let operation_span = span(&[left.span()?, right.span()?]);
|
||||
let operation_span = span(&[left.span(), right.span()]);
|
||||
match operator.item {
|
||||
Operator::Math(Math::Plus) => match lhs.append_df(rhs, Axis::Row, operation_span) {
|
||||
Ok(df) => Ok(df.into_value(operation_span)),
|
||||
@ -26,9 +26,9 @@ pub(super) fn between_dataframes(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ pub(super) fn compute_between_series(
|
||||
right: &Value,
|
||||
rhs: &Series,
|
||||
) -> Result<Value, ShellError> {
|
||||
let operation_span = span(&[left.span()?, right.span()?]);
|
||||
let operation_span = span(&[left.span(), right.span()]);
|
||||
match operator.item {
|
||||
Operator::Math(Math::Plus) => {
|
||||
let mut res = lhs + rhs;
|
||||
@ -71,7 +71,7 @@ pub(super) fn compute_between_series(
|
||||
Err(e) => Err(ShellError::GenericError(
|
||||
"Division error".into(),
|
||||
e.to_string(),
|
||||
Some(right.span()?),
|
||||
Some(right.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
@ -79,32 +79,32 @@ pub(super) fn compute_between_series(
|
||||
}
|
||||
Operator::Comparison(Comparison::Equal) => {
|
||||
let name = format!("eq_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Comparison(Comparison::NotEqual) => {
|
||||
let name = format!("neq_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Comparison(Comparison::LessThan) => {
|
||||
let name = format!("lt_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Comparison(Comparison::LessThanOrEqual) => {
|
||||
let name = format!("lte_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Comparison(Comparison::GreaterThan) => {
|
||||
let name = format!("gt_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Comparison(Comparison::GreaterThanOrEqual) => {
|
||||
let name = format!("gte_{}_{}", lhs.name(), rhs.name());
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span().ok(), Series::equal)?;
|
||||
let res = compare_series(lhs, rhs, name.as_str(), right.span(), Series::equal)?;
|
||||
NuDataFrame::series_to_value(res, operation_span)
|
||||
}
|
||||
Operator::Boolean(Boolean::And) => match lhs.dtype() {
|
||||
@ -122,7 +122,7 @@ pub(super) fn compute_between_series(
|
||||
_ => Err(ShellError::GenericError(
|
||||
"Incompatible types".into(),
|
||||
"unable to cast to boolean".into(),
|
||||
Some(right.span()?),
|
||||
Some(right.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
@ -151,7 +151,7 @@ pub(super) fn compute_between_series(
|
||||
_ => Err(ShellError::GenericError(
|
||||
"Incompatible types".into(),
|
||||
"unable to cast to boolean".into(),
|
||||
Some(right.span()?),
|
||||
Some(right.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
@ -168,9 +168,9 @@ pub(super) fn compute_between_series(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -179,7 +179,7 @@ fn compare_series<'s, F>(
|
||||
lhs: &'s Series,
|
||||
rhs: &'s Series,
|
||||
name: &'s str,
|
||||
span: Option<Span>,
|
||||
span: Span,
|
||||
f: F,
|
||||
) -> Result<Series, ShellError>
|
||||
where
|
||||
@ -190,7 +190,7 @@ where
|
||||
ShellError::GenericError(
|
||||
"Equality error".into(),
|
||||
e.to_string(),
|
||||
span,
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
)
|
||||
@ -211,13 +211,13 @@ pub(super) fn compute_series_single_value(
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
});
|
||||
}
|
||||
|
||||
let lhs_span = left.span()?;
|
||||
let lhs_span = left.span();
|
||||
let lhs = lhs.as_series(lhs_span)?;
|
||||
|
||||
match operator.item {
|
||||
@ -232,9 +232,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Math(Math::Minus) => match &right {
|
||||
@ -247,9 +247,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Math(Math::Multiply) => match &right {
|
||||
@ -262,9 +262,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Math(Math::Divide) => match &right {
|
||||
@ -285,9 +285,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::Equal) => match &right {
|
||||
@ -305,9 +305,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::NotEqual) => match &right {
|
||||
@ -326,9 +326,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::LessThan) => match &right {
|
||||
@ -342,9 +342,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::LessThanOrEqual) => match &right {
|
||||
@ -358,9 +358,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::GreaterThan) => match &right {
|
||||
@ -374,9 +374,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::GreaterThanOrEqual) => match &right {
|
||||
@ -390,9 +390,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
// TODO: update this to do a regex match instead of a simple contains?
|
||||
@ -401,9 +401,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::StartsWith) => match &right {
|
||||
@ -414,9 +414,9 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
Operator::Comparison(Comparison::EndsWith) => match &right {
|
||||
@ -427,17 +427,17 @@ pub(super) fn compute_series_single_value(
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
},
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
lhs_ty: left.get_type().to_string(),
|
||||
lhs_span: left.span()?,
|
||||
lhs_span: left.span(),
|
||||
rhs_ty: right.get_type().to_string(),
|
||||
rhs_span: right.span()?,
|
||||
rhs_span: right.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -882,6 +882,7 @@ fn series_to_values(
|
||||
span,
|
||||
Span::unknown(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -897,6 +898,7 @@ fn series_to_values(
|
||||
span,
|
||||
Span::unknown(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -950,6 +952,7 @@ fn series_to_values(
|
||||
span,
|
||||
Span::unknown(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -965,6 +968,7 @@ fn series_to_values(
|
||||
span,
|
||||
Span::unknown(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -235,7 +235,7 @@ impl NuDataFrame {
|
||||
if Self::can_downcast(&value) {
|
||||
Ok(Self::get_df(value)?)
|
||||
} else if NuLazyFrame::can_downcast(&value) {
|
||||
let span = value.span()?;
|
||||
let span = value.span();
|
||||
let lazy = NuLazyFrame::try_from_value(value)?;
|
||||
let df = lazy.collect(span)?;
|
||||
Ok(df)
|
||||
@ -243,7 +243,7 @@ impl NuDataFrame {
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
@ -266,7 +266,7 @@ impl NuDataFrame {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "dataframe".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -70,17 +70,17 @@ fn compute_with_value(
|
||||
|
||||
match rhs.as_ref() {
|
||||
polars::prelude::Expr::Literal(..) => {
|
||||
with_operator(operator, left, rhs, lhs_span, right.span()?, op)
|
||||
with_operator(operator, left, rhs, lhs_span, right.span(), op)
|
||||
}
|
||||
_ => Err(ShellError::TypeMismatch {
|
||||
err_message: "Only literal expressions or number".into(),
|
||||
span: right.span()?,
|
||||
span: right.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let rhs = NuExpression::try_from_value(right.clone())?;
|
||||
with_operator(operator, left, &rhs, lhs_span, right.span()?, op)
|
||||
with_operator(operator, left, &rhs, lhs_span, right.span(), op)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ impl NuExpression {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
@ -157,7 +157,7 @@ impl ExtractedExpr {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ impl NuLazyFrame {
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
@ -164,7 +164,7 @@ impl NuLazyFrame {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy frame".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ impl NuLazyGroupBy {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy groupby".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl NuWhen {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "when expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ pub(crate) fn convert_columns(
|
||||
Vec::new(),
|
||||
)
|
||||
})
|
||||
.and_then(|v| v.span())?;
|
||||
.map(|v| v.span())?;
|
||||
|
||||
let res = columns
|
||||
.into_iter()
|
||||
@ -61,7 +61,7 @@ pub(crate) fn convert_columns_string(
|
||||
Vec::new(),
|
||||
)
|
||||
})
|
||||
.and_then(|v| v.span())?;
|
||||
.map(|v| v.span())?;
|
||||
|
||||
let res = columns
|
||||
.into_iter()
|
||||
|
@ -90,8 +90,9 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -256,8 +256,9 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "integer, filesize, string, date, duration, binary or bool".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -160,8 +160,9 @@ fn operate(value: Value, head: Span, signed: bool, number_size: NumberBytes) ->
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -90,8 +90,9 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -146,8 +147,9 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -150,8 +151,9 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -140,6 +141,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -169,8 +171,9 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -130,6 +131,7 @@ where
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -159,8 +161,9 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,9 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
||||
exp_input_type: "integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -91,8 +91,9 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
exp_input_type: "float , integer or filesize".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ fn vertical_rotate_value(
|
||||
}
|
||||
_ => Err(ShellError::TypeMismatch {
|
||||
err_message: "list".to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,7 @@ fn horizontal_rotate_value(
|
||||
}
|
||||
_ => Err(ShellError::TypeMismatch {
|
||||
err_message: "record".to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,10 @@ fn process_cell(
|
||||
redirect_stderr,
|
||||
) {
|
||||
Ok(pd) => pd.into_value(span),
|
||||
Err(e) => Value::Error { error: Box::new(e) },
|
||||
Err(e) => Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,8 +99,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,8 +89,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,8 +100,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span: head,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,8 +89,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -85,8 +85,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,8 +89,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -95,8 +95,9 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,9 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
exp_input_type: "numeric".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +140,7 @@ fn operate(
|
||||
if let Err(error) = r {
|
||||
return Value::Error {
|
||||
error: Box::new(error),
|
||||
span: head,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -170,6 +171,7 @@ fn action(
|
||||
"please supply foreground and/or background color parameters".into(),
|
||||
span: command_span,
|
||||
}),
|
||||
span: command_span,
|
||||
}
|
||||
}
|
||||
(None, None, None, Some(bg_end)) => {
|
||||
@ -295,8 +297,9 @@ fn action(
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::TypeMismatch {
|
||||
err_message: got,
|
||||
span: other.span().unwrap_or(command_span),
|
||||
span: other.span(),
|
||||
}),
|
||||
span: other.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ fn operate(
|
||||
|
||||
if column_paths.is_empty() {
|
||||
input.map(
|
||||
move |v| process_value(&v, &text, command_span),
|
||||
move |v| process_value(&v, &text),
|
||||
engine_state.ctrlc.clone(),
|
||||
)
|
||||
} else {
|
||||
@ -116,20 +116,18 @@ fn process_each_path(
|
||||
command_span: Span,
|
||||
) -> Value {
|
||||
for path in column_paths {
|
||||
let ret = value.update_cell_path(
|
||||
&path.members,
|
||||
Box::new(|v| process_value(v, text, command_span)),
|
||||
);
|
||||
let ret = value.update_cell_path(&path.members, Box::new(|v| process_value(v, text)));
|
||||
if let Err(error) = ret {
|
||||
return Value::Error {
|
||||
error: Box::new(error),
|
||||
span: command_span,
|
||||
};
|
||||
}
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn process_value(value: &Value, text: &Option<String>, command_span: Span) -> Value {
|
||||
fn process_value(value: &Value, text: &Option<String>) -> Value {
|
||||
match value {
|
||||
Value::String { val, span } => {
|
||||
let text = text.as_deref().unwrap_or(val.as_str());
|
||||
@ -142,8 +140,9 @@ fn process_value(value: &Value, text: &Option<String>, command_span: Span) -> Va
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::TypeMismatch {
|
||||
err_message: got,
|
||||
span: other.span().unwrap_or(command_span),
|
||||
span: other.span(),
|
||||
}),
|
||||
span: other.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,8 +113,9 @@ fn action(
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.expect_span(),
|
||||
input.span(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
},
|
||||
Value::String { val, .. } => {
|
||||
@ -125,8 +126,9 @@ fn action(
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.expect_span(),
|
||||
input.span(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
|
||||
ActionType::Decode => match hex_decode(val.as_ref()) {
|
||||
@ -139,6 +141,7 @@ fn action(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
Err(HexDecodingError::InvalidDigit(index, digit)) => Value::Error {
|
||||
error: Box::new(ShellError::GenericError(
|
||||
@ -148,6 +151,7 @@ fn action(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: command_span,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -155,8 +159,9 @@ fn action(
|
||||
other => Value::Error {
|
||||
error: Box::new(ShellError::TypeMismatch {
|
||||
err_message: format!("string or binary, not {}", other.get_type()),
|
||||
span: other.span().unwrap_or(command_span),
|
||||
span: other.span(),
|
||||
}),
|
||||
span: other.span(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl Command for Format {
|
||||
Err(e) => Err(e),
|
||||
Ok(pattern) => {
|
||||
let string_pattern = pattern.as_string()?;
|
||||
let string_span = pattern.span()?;
|
||||
let string_span = pattern.span();
|
||||
// the string span is start as `"`, we don't need the character
|
||||
// to generate proper span for sub expression.
|
||||
let ops = extract_formatting_operations(
|
||||
@ -233,13 +233,13 @@ fn format(
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
_ => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record".to_string(),
|
||||
wrong_type: val.get_type().to_string(),
|
||||
dst_span: head_span,
|
||||
src_span: val.expect_span(),
|
||||
src_span: val.span(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -252,12 +252,12 @@ fn format(
|
||||
}
|
||||
// Unwrapping this ShellError is a bit unfortunate.
|
||||
// Ideally, its Span would be preserved.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
_ => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record".to_string(),
|
||||
wrong_type: data_as_value.get_type().to_string(),
|
||||
dst_span: head_span,
|
||||
src_span: data_as_value.expect_span(),
|
||||
src_span: data_as_value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +67,9 @@ where
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: input.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: input.expect_span(),
|
||||
src_span: input.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl Command for Do {
|
||||
}
|
||||
|
||||
let span = if let Some(rest_item) = rest_items.first() {
|
||||
rest_item.span()?
|
||||
rest_item.span()
|
||||
} else {
|
||||
call.head
|
||||
};
|
||||
|
@ -73,6 +73,7 @@ impl Command for ErrorMake {
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
@ -93,6 +94,7 @@ impl Command for ErrorMake {
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span: Span::unknown(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
@ -126,10 +128,7 @@ fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
|
||||
let label_end = label.get_data_by_key("end");
|
||||
let label_text = label.get_data_by_key("text");
|
||||
|
||||
let label_span = match label.span() {
|
||||
Ok(lspan) => Some(lspan),
|
||||
Err(_) => None,
|
||||
};
|
||||
let label_span = Some(label.span());
|
||||
|
||||
match (label_start, label_end, label_text) {
|
||||
(
|
||||
|
@ -105,7 +105,7 @@ impl Command for If {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: result.span()?,
|
||||
span: result.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl Command for Try {
|
||||
let err_record = err_to_record(error, call.head);
|
||||
handle_catch(err_record, catch_block, engine_state, stack)
|
||||
}
|
||||
Ok(PipelineData::Value(Value::Error { error }, ..)) => {
|
||||
Ok(PipelineData::Value(Value::Error { error, .. }, ..)) => {
|
||||
let error = intercept_block_control(*error)?;
|
||||
let err_record = err_to_record(error, call.head);
|
||||
handle_catch(err_record, catch_block, engine_state, stack)
|
||||
@ -141,7 +141,7 @@ fn err_to_record(error: ShellError, head: Span) -> Value {
|
||||
record! {
|
||||
"msg" => Value::string(error.to_string(), head),
|
||||
"debug" => Value::string(format!("{error:?}"), head),
|
||||
"raw" => Value::error(error),
|
||||
"raw" => Value::error(error, head),
|
||||
},
|
||||
head,
|
||||
)
|
||||
|
@ -86,7 +86,7 @@ impl Command for While {
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "bool".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: result.span()?,
|
||||
span: result.span(),
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
|
@ -137,8 +137,9 @@ fn add(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +178,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
err_message: "End must be greater than or equal to Start".to_string(),
|
||||
span: head,
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
Ordering::Less => Value::Binary {
|
||||
val: {
|
||||
@ -210,8 +211,9 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
format!("input type: {:?}", other.get_type()),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
)),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ impl Command for BytesBuild {
|
||||
match val {
|
||||
Value::Binary { mut val, .. } => output.append(&mut val),
|
||||
// Explicitly propagate errors instead of dropping them.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
other => {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "only binary data arguments are supported".to_string(),
|
||||
span: other.expect_span(),
|
||||
span: other.span(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -55,13 +55,13 @@ impl Command for BytesCollect {
|
||||
}
|
||||
}
|
||||
// Explicitly propagate errors instead of dropping them.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
other => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -101,8 +101,9 @@ fn ends_with(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -143,8 +143,9 @@ fn index_of(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -86,8 +86,9 @@ fn length(val: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -149,8 +149,9 @@ fn remove(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -141,8 +141,9 @@ fn replace(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,9 @@ fn reverse(val: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,9 @@ impl Command for BytesStartsWith {
|
||||
exp_input_type: "string and binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
}
|
||||
.into_pipeline_data());
|
||||
}
|
||||
@ -158,8 +159,9 @@ fn starts_with(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -79,12 +79,12 @@ impl HashableValue {
|
||||
Value::Binary { val, span } => Ok(HashableValue::Binary { val, span }),
|
||||
|
||||
// Explicitly propagate errors instead of dropping them.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"input value is not hashable".into(),
|
||||
format!("input type: {:?}", value.get_type()),
|
||||
span,
|
||||
value.expect_span(),
|
||||
value.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -237,6 +237,7 @@ mod test {
|
||||
Value::Nothing { span },
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::DidYouMean("what?".to_string(), span)),
|
||||
span,
|
||||
},
|
||||
Value::CellPath {
|
||||
val: CellPath {
|
||||
|
@ -142,7 +142,7 @@ impl Command for Histogram {
|
||||
calc_method,
|
||||
span,
|
||||
// Note that as_list() filters out Value::Error here.
|
||||
data_as_value.expect_span(),
|
||||
data_as_value.span(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -164,10 +164,10 @@ fn run_histogram(
|
||||
for v in values {
|
||||
match v {
|
||||
// Propagate existing errors.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
_ => {
|
||||
let t = v.get_type();
|
||||
let span = v.expect_span();
|
||||
let span = v.span();
|
||||
inputs.push(HashableValue::from_value(v, head_span).map_err(|_| {
|
||||
ShellError::UnsupportedInput(
|
||||
"Since --column-name was not provided, only lists of hashable values are supported.".to_string(),
|
||||
@ -202,7 +202,7 @@ fn run_histogram(
|
||||
}
|
||||
}
|
||||
// Propagate existing errors.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
|
@ -203,8 +203,9 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
exp_input_type: "int, filesize, float, string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -204,8 +204,9 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
||||
.into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -161,6 +161,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
Ok(val) => Value::Bool { val, span },
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
},
|
||||
},
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
@ -170,8 +171,9 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
exp_input_type: "bool, integer, float or string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -264,8 +264,9 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -308,6 +309,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
input.debug_value(),
|
||||
*span,
|
||||
)),
|
||||
span: *span,
|
||||
},
|
||||
},
|
||||
Zone::West(i) => match FixedOffset::west_opt((*i as i32) * HOUR) {
|
||||
@ -323,6 +325,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
input.debug_value(),
|
||||
*span,
|
||||
)),
|
||||
span: *span,
|
||||
},
|
||||
},
|
||||
Zone::Error => Value::Error {
|
||||
@ -331,6 +334,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
err_message: "Invalid timezone or offset".to_string(),
|
||||
span: *span,
|
||||
}),
|
||||
span: *span,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -346,6 +350,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
Err(reason) => {
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::CantConvert { to_type: format!("could not parse as datetime using format '{}'", dt.0), from_type: reason.to_string(), span: head, help: Some("you can use `into datetime` without a format string to enable flexible parsing".to_string()) }),
|
||||
span: head,
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -369,8 +374,9 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
span: *span,
|
||||
help: None,
|
||||
}),
|
||||
span: *span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -125,8 +126,9 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
exp_input_type: "string, integer or bool".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ fn into_duration(
|
||||
if let Err(error) = r {
|
||||
return Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -235,6 +236,7 @@ fn action(input: &Value, span: Span) -> Value {
|
||||
Ok(val) => Value::Duration { val, span },
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
},
|
||||
},
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
@ -244,8 +246,9 @@ fn action(input: &Value, span: Span) -> Value {
|
||||
exp_input_type: "string or duration".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -270,7 +273,7 @@ mod test {
|
||||
#[case("4\u{00B5}s", 4*1000)] // micro sign
|
||||
#[case("4\u{03BC}s", 4*1000)] // mu symbol
|
||||
#[case("5ms", 5 * 1000 * 1000)]
|
||||
#[case("1sec", 1 * NS_PER_SEC)]
|
||||
#[case("1sec", NS_PER_SEC)]
|
||||
#[case("7min", 7 * 60 * NS_PER_SEC)]
|
||||
#[case("42hr", 42 * 60 * 60 * NS_PER_SEC)]
|
||||
#[case("123day", 123 * 24 * 60 * 60 * NS_PER_SEC)]
|
||||
|
@ -148,42 +148,40 @@ impl Command for SubCommand {
|
||||
}
|
||||
|
||||
pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
if let Ok(value_span) = input.span() {
|
||||
match input {
|
||||
Value::Filesize { .. } => input.clone(),
|
||||
Value::Int { val, .. } => Value::Filesize {
|
||||
val: *val,
|
||||
let value_span = input.span();
|
||||
match input {
|
||||
Value::Filesize { .. } => input.clone(),
|
||||
Value::Int { val, .. } => Value::Filesize {
|
||||
val: *val,
|
||||
span: value_span,
|
||||
},
|
||||
Value::Float { val, .. } => Value::Filesize {
|
||||
val: *val as i64,
|
||||
span: value_span,
|
||||
},
|
||||
Value::String { val, .. } => match int_from_string(val, value_span) {
|
||||
Ok(val) => Value::Filesize {
|
||||
val,
|
||||
span: value_span,
|
||||
},
|
||||
Value::Float { val, .. } => Value::Filesize {
|
||||
val: *val as i64,
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: value_span,
|
||||
},
|
||||
Value::String { val, .. } => match int_from_string(val, value_span) {
|
||||
Ok(val) => Value::Filesize {
|
||||
val,
|
||||
span: value_span,
|
||||
},
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
},
|
||||
},
|
||||
Value::Nothing { .. } => Value::Filesize {
|
||||
val: 0,
|
||||
span: value_span,
|
||||
},
|
||||
other => Value::Error {
|
||||
error: Box::new(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
}),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
// Propagate existing errors
|
||||
input.clone()
|
||||
},
|
||||
Value::Nothing { .. } => Value::Filesize {
|
||||
val: 0,
|
||||
span: value_span,
|
||||
},
|
||||
other => Value::Error {
|
||||
error: Box::new(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
|
@ -250,6 +250,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -263,6 +264,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
Ok(val) => Value::Int { val, span },
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
@ -297,6 +299,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
val_span: *val_span,
|
||||
call_span: span,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
} else {
|
||||
Value::Int {
|
||||
@ -335,8 +338,9 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
.into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -353,7 +357,12 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
{
|
||||
match int_from_string(val, head) {
|
||||
Ok(x) => return Value::int(x, head),
|
||||
Err(e) => return Value::Error { error: Box::new(e) },
|
||||
Err(e) => {
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span: head,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if val.starts_with("00") {
|
||||
// It's a padded string
|
||||
@ -367,6 +376,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
span: head,
|
||||
help: Some(e.to_string()),
|
||||
}),
|
||||
span: head,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -381,8 +391,9 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head,
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -395,6 +406,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
span: head,
|
||||
help: None,
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -583,7 +595,7 @@ mod test {
|
||||
},
|
||||
Span::test_data(),
|
||||
);
|
||||
if let Value::Error { error } = actual {
|
||||
if let Value::Error { error, .. } = actual {
|
||||
if let ShellError::IncorrectValue { msg: e, .. } = *error {
|
||||
assert!(
|
||||
e.contains(err_expected),
|
||||
|
@ -176,8 +176,9 @@ fn into_record(
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: call.head,
|
||||
},
|
||||
};
|
||||
Ok(res.into_pipeline_data())
|
||||
|
@ -249,7 +249,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span,
|
||||
},
|
||||
|
||||
Value::Error { error } => Value::String {
|
||||
Value::Error { error, .. } => Value::String {
|
||||
val: into_code(error).unwrap_or_default(),
|
||||
span,
|
||||
},
|
||||
@ -265,6 +265,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span,
|
||||
help: Some("try using the `to nuon` command".into()),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
Value::Binary { .. } => Value::Error {
|
||||
error: Box::new(ShellError::CantConvert {
|
||||
@ -273,6 +274,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span,
|
||||
help: Some("try using the `decode` command".into()),
|
||||
}),
|
||||
span,
|
||||
},
|
||||
x => Value::Error {
|
||||
error: Box::new(ShellError::CantConvert {
|
||||
@ -281,6 +283,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -213,12 +213,12 @@ fn action(
|
||||
Ok(Value::Nothing { span: *span })
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -261,7 +261,7 @@ fn nu_value_to_string(value: Value, separator: &str) -> String {
|
||||
Value::Block { val, .. } => format!("<Block {val}>"),
|
||||
Value::Closure { val, .. } => format!("<Closure {val}>"),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{error:?}"),
|
||||
Value::Error { error, .. } => format!("{error:?}"),
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
|
@ -72,7 +72,7 @@ impl SQLiteDatabase {
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "database".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
@ -459,6 +459,7 @@ pub fn convert_sqlite_value_to_nu_value(value: ValueRef, span: Span) -> Value {
|
||||
Err(_) => {
|
||||
return Value::Error {
|
||||
error: Box::new(ShellError::NonUtf8(span)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -91,6 +91,7 @@ fn helper(value: Value, head: Span) -> Value {
|
||||
},
|
||||
_ => Value::Error {
|
||||
error: Box::new(ShellError::DatetimeParseError(value.debug_value(), head)),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -166,6 +166,7 @@ fn helper(val: Value, head: Span) -> Value {
|
||||
Value::Date { val, span: _ } => parse_date_into_table(val, head),
|
||||
_ => Value::Error {
|
||||
error: Box::new(DatetimeParseError(val.debug_value(), head)),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,7 @@ fn helper(val: Value, head: Span) -> Value {
|
||||
Value::Date { val, span: _ } => parse_date_into_table(val, head),
|
||||
_ => Value::Error {
|
||||
error: Box::new(DatetimeParseError(val.debug_value(), head)),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,7 @@ fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
|
||||
}
|
||||
_ => Value::Error {
|
||||
error: Box::new(ShellError::DatetimeParseError(value.debug_value(), head)),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -140,6 +141,7 @@ fn _to_timezone(dt: DateTime<FixedOffset>, timezone: &Spanned<String>, span: Spa
|
||||
err_message: String::from("invalid time zone"),
|
||||
span: timezone.span,
|
||||
}),
|
||||
span: timezone.span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,13 @@ pub(crate) fn parse_date_from_string(
|
||||
LocalResult::Ambiguous(d, _) => Ok(d),
|
||||
LocalResult::None => Err(Value::Error {
|
||||
error: Box::new(ShellError::DatetimeParseError(input.to_string(), span)),
|
||||
span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
Err(_) => Err(Value::Error {
|
||||
error: Box::new(ShellError::DatetimeParseError(input.to_string(), span)),
|
||||
span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ pub fn get_pipeline_elements(
|
||||
};
|
||||
let index = format!("{pipeline_idx}_{i}");
|
||||
let value_type = value.get_type();
|
||||
let value_span = value.span()?;
|
||||
let value_span = value.span();
|
||||
let value_span_start = value_span.start as i64;
|
||||
let value_span_end = value_span.end as i64;
|
||||
let command_name = command_name;
|
||||
@ -150,7 +150,7 @@ fn get_arguments(engine_state: &EngineState, stack: &mut Stack, call: Call) -> V
|
||||
let arg_type = "expr";
|
||||
let arg_value_name = debug_string_without_formatting(&evaluated_expression);
|
||||
let arg_value_type = &evaluated_expression.get_type().to_string();
|
||||
let evaled_span = evaluated_expression.expect_span();
|
||||
let evaled_span = evaluated_expression.span();
|
||||
let arg_value_name_span_start = evaled_span.start as i64;
|
||||
let arg_value_name_span_end = evaled_span.end as i64;
|
||||
|
||||
@ -169,7 +169,7 @@ fn get_arguments(engine_state: &EngineState, stack: &mut Stack, call: Call) -> V
|
||||
let evaluated_expression = get_expression_as_value(engine_state, stack, inner_expr);
|
||||
let arg_value_name = debug_string_without_formatting(&evaluated_expression);
|
||||
let arg_value_type = &evaluated_expression.get_type().to_string();
|
||||
let evaled_span = evaluated_expression.expect_span();
|
||||
let evaled_span = evaluated_expression.span();
|
||||
let arg_value_name_span_start = evaled_span.start as i64;
|
||||
let arg_value_name_span_end = evaled_span.end as i64;
|
||||
|
||||
@ -187,7 +187,7 @@ fn get_arguments(engine_state: &EngineState, stack: &mut Stack, call: Call) -> V
|
||||
let evaluated_expression = get_expression_as_value(engine_state, stack, inner_expr);
|
||||
let arg_value_name = debug_string_without_formatting(&evaluated_expression);
|
||||
let arg_value_type = &evaluated_expression.get_type().to_string();
|
||||
let evaled_span = evaluated_expression.expect_span();
|
||||
let evaled_span = evaluated_expression.span();
|
||||
let arg_value_name_span_start = evaled_span.start as i64;
|
||||
let arg_value_name_span_end = evaled_span.end as i64;
|
||||
|
||||
@ -215,6 +215,7 @@ fn get_expression_as_value(
|
||||
Ok(v) => v,
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: inner_expr.span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -257,7 +258,7 @@ pub fn debug_string_without_formatting(value: &Value) -> String {
|
||||
Value::Block { val, .. } => format!("<Block {val}>"),
|
||||
Value::Closure { val, .. } => format!("<Closure {val}>"),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{error:?}"),
|
||||
Value::Error { error, .. } => format!("{error:?}"),
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
|
@ -116,18 +116,17 @@ fn build_metadata_record(
|
||||
) -> Value {
|
||||
let mut record = Record::new();
|
||||
|
||||
if let Ok(span) = arg.span() {
|
||||
record.push(
|
||||
"span",
|
||||
Value::record(
|
||||
record! {
|
||||
"start" => Value::int(span.start as i64,span),
|
||||
"end" => Value::int(span.end as i64, span),
|
||||
},
|
||||
head,
|
||||
),
|
||||
);
|
||||
}
|
||||
let span = arg.span();
|
||||
record.push(
|
||||
"span",
|
||||
Value::record(
|
||||
record! {
|
||||
"start" => Value::int(span.start as i64,span),
|
||||
"end" => Value::int(span.end as i64, span),
|
||||
},
|
||||
head,
|
||||
),
|
||||
);
|
||||
|
||||
if let Some(x) = metadata.as_deref() {
|
||||
match x {
|
||||
|
@ -34,7 +34,7 @@ impl Command for ViewSource {
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let arg: Value = call.req(engine_state, stack, 0)?;
|
||||
let arg_span = arg.span()?;
|
||||
let arg_span = arg.span();
|
||||
|
||||
match arg {
|
||||
Value::Block { val: block_id, .. } | Value::Closure { val: block_id, .. } => {
|
||||
|
@ -402,6 +402,7 @@ fn interactive_copy(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
} else if !confirmed {
|
||||
let msg = format!("{:} not copied to {:}", src.display(), dst.display());
|
||||
@ -541,6 +542,7 @@ fn copy_symlink(
|
||||
None,
|
||||
vec![],
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -574,6 +576,7 @@ fn copy_symlink(
|
||||
None,
|
||||
vec![],
|
||||
)),
|
||||
span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -617,5 +620,6 @@ fn convert_io_error(error: std::io::Error, src: PathBuf, dst: PathBuf, span: Spa
|
||||
|
||||
Value::Error {
|
||||
error: Box::new(shell_error),
|
||||
span,
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ impl Command for Glob {
|
||||
}) =
|
||||
call.get_flag(engine_state, stack, "not")?
|
||||
{
|
||||
let p = convert_patterns(pats.as_slice(), span)?;
|
||||
let p = convert_patterns(pats.as_slice())?;
|
||||
(p, pat_span)
|
||||
} else {
|
||||
(vec![], span)
|
||||
@ -226,14 +226,14 @@ impl Command for Glob {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_patterns(columns: &[Value], span: Span) -> Result<Vec<String>, ShellError> {
|
||||
fn convert_patterns(columns: &[Value]) -> Result<Vec<String>, ShellError> {
|
||||
let res = columns
|
||||
.iter()
|
||||
.map(|value| match &value {
|
||||
Value::String { val: s, .. } => Ok(s.clone()),
|
||||
_ => Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "Incorrect column format, Only string as column name".to_string(),
|
||||
span: value.span().unwrap_or(span),
|
||||
span: value.span(),
|
||||
}),
|
||||
})
|
||||
.collect::<Result<Vec<String>, _>>()?;
|
||||
|
@ -257,11 +257,13 @@ impl Command for Ls {
|
||||
Ok(value) => Some(value),
|
||||
Err(err) => Some(Value::Error {
|
||||
error: Box::new(err),
|
||||
span: call_span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
Err(err) => Some(Value::Error {
|
||||
error: Box::new(err),
|
||||
span: call_span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user