forked from extern/nushell
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:
@ -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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +202,7 @@ impl Command for Mv {
|
||||
if let Err(error) = result {
|
||||
Some(Value::Error {
|
||||
error: Box::new(error),
|
||||
span: spanned_source.span,
|
||||
})
|
||||
} else if verbose {
|
||||
let val = match result {
|
||||
|
@ -430,6 +430,7 @@ fn rm(
|
||||
let msg = format!("Could not delete {:}: {e:}", f.to_string_lossy());
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::RemoveNotPossible(msg, span)),
|
||||
span,
|
||||
}
|
||||
} else if verbose {
|
||||
let msg = if interactive && !confirmed {
|
||||
@ -452,6 +453,7 @@ fn rm(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -464,6 +466,7 @@ fn rm(
|
||||
None,
|
||||
Vec::new(),
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -263,7 +263,7 @@ fn value_to_bytes(value: Value) -> Result<Vec<u8>, ShellError> {
|
||||
Ok(val.into_bytes())
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Ok(other.as_string()?.into_bytes()),
|
||||
}
|
||||
}
|
||||
@ -385,13 +385,13 @@ fn stream_to_file(
|
||||
Value::String { val, .. } => val.into_bytes(),
|
||||
Value::Binary { val, .. } => val,
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
other => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string or binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -138,12 +138,12 @@ fn getcol(
|
||||
.into_pipeline_data(ctrlc)
|
||||
.set_metadata(metadata)),
|
||||
// Propagate errors
|
||||
PipelineData::Value(Value::Error { error }, ..) => Err(*error),
|
||||
PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error),
|
||||
PipelineData::Value(other, ..) => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
PipelineData::ExternalStream { .. } => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".into(),
|
||||
|
@ -196,7 +196,7 @@ fn extract_int_or_range(
|
||||
.or(range_opt)
|
||||
.ok_or_else(|| ShellError::TypeMismatch {
|
||||
err_message: "int or range".into(),
|
||||
span: value.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
span: value.span(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ with 'transpose' first."#
|
||||
}
|
||||
|
||||
let input_span = x.span();
|
||||
let x_is_error = x.is_error();
|
||||
match eval_block_with_early_return(
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
@ -169,9 +170,10 @@ with 'transpose' first."#
|
||||
Err(ShellError::Continue(v)) => Some(Value::nothing(v)),
|
||||
Err(ShellError::Break(_)) => None,
|
||||
Err(error) => {
|
||||
let error = chain_error_with_input(error, input_span);
|
||||
let error = chain_error_with_input(error, x_is_error, input_span);
|
||||
Some(Value::Error {
|
||||
error: Box::new(error),
|
||||
span: input_span,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -196,6 +198,7 @@ with 'transpose' first."#
|
||||
Err(err) => {
|
||||
return Some(Value::Error {
|
||||
error: Box::new(err),
|
||||
span,
|
||||
})
|
||||
}
|
||||
};
|
||||
@ -207,6 +210,8 @@ with 'transpose' first."#
|
||||
}
|
||||
|
||||
let input_span = x.span();
|
||||
let x_is_error = x.is_error();
|
||||
|
||||
match eval_block_with_early_return(
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
@ -219,8 +224,12 @@ with 'transpose' first."#
|
||||
Err(ShellError::Continue(v)) => Some(Value::nothing(v)),
|
||||
Err(ShellError::Break(_)) => None,
|
||||
Err(error) => {
|
||||
let error = Box::new(chain_error_with_input(error, input_span));
|
||||
Some(Value::Error { error })
|
||||
let error =
|
||||
Box::new(chain_error_with_input(error, x_is_error, input_span));
|
||||
Some(Value::Error {
|
||||
error,
|
||||
span: input_span,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -102,7 +102,8 @@ a variable. On the other hand, the "row condition" syntax is not supported."#
|
||||
}
|
||||
}
|
||||
Err(error) => Some(Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, x.span())),
|
||||
error: Box::new(chain_error_with_input(error, x.is_error(), x.span())),
|
||||
span: x.span(),
|
||||
}),
|
||||
}
|
||||
})
|
||||
@ -122,6 +123,7 @@ a variable. On the other hand, the "row condition" syntax is not supported."#
|
||||
Err(err) => {
|
||||
return Some(Value::Error {
|
||||
error: Box::new(err),
|
||||
span,
|
||||
})
|
||||
}
|
||||
};
|
||||
@ -149,7 +151,8 @@ a variable. On the other hand, the "row condition" syntax is not supported."#
|
||||
}
|
||||
}
|
||||
Err(error) => Some(Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, x.span())),
|
||||
error: Box::new(chain_error_with_input(error, x.is_error(), x.span())),
|
||||
span: x.span(),
|
||||
}),
|
||||
}
|
||||
})
|
||||
@ -182,7 +185,8 @@ a variable. On the other hand, the "row condition" syntax is not supported."#
|
||||
}
|
||||
}
|
||||
Err(error) => Some(Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, x.span())),
|
||||
error: Box::new(chain_error_with_input(error, x.is_error(), x.span())),
|
||||
span: x.span(),
|
||||
}),
|
||||
}
|
||||
.into_pipeline_data(ctrlc))
|
||||
|
@ -366,13 +366,7 @@ fn find_with_rest_and_highlight(
|
||||
let terms = call.rest::<Value>(&engine_state, stack, 0)?;
|
||||
let lower_terms = terms
|
||||
.iter()
|
||||
.map(|v| {
|
||||
if let Ok(span) = v.span() {
|
||||
Value::string(v.into_string("", &config).to_lowercase(), span)
|
||||
} else {
|
||||
v.clone()
|
||||
}
|
||||
})
|
||||
.map(|v| Value::string(v.into_string("", &config).to_lowercase(), span))
|
||||
.collect::<Vec<Value>>();
|
||||
|
||||
let style_computer = StyleComputer::from_config(&engine_state, stack);
|
||||
@ -482,14 +476,14 @@ fn find_with_rest_and_highlight(
|
||||
}
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => return Err(*error),
|
||||
Value::Error { error, .. } => return Err(*error),
|
||||
other => {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"unsupported type from raw stream".into(),
|
||||
format!("input: {:?}", other.get_type()),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
},
|
||||
@ -510,11 +504,7 @@ fn value_should_be_printed(
|
||||
columns_to_search: &Vec<String>,
|
||||
invert: bool,
|
||||
) -> bool {
|
||||
let lower_value = if let Ok(span) = value.span() {
|
||||
Value::string(value.into_string("", filter_config).to_lowercase(), span)
|
||||
} else {
|
||||
value.clone()
|
||||
};
|
||||
let lower_value = Value::string(value.into_string("", filter_config).to_lowercase(), span);
|
||||
|
||||
let mut match_found = lower_terms.iter().any(|term| match value {
|
||||
Value::Bool { .. }
|
||||
@ -579,7 +569,7 @@ fn record_matches_term(
|
||||
if !cols_to_search.contains(col) {
|
||||
return false;
|
||||
}
|
||||
let lower_val = if val.span().is_ok() {
|
||||
let lower_val = if !val.is_error() {
|
||||
Value::string(
|
||||
val.into_string("", filter_config).to_lowercase(),
|
||||
Span::test_data(),
|
||||
|
@ -164,12 +164,12 @@ fn first_helper(
|
||||
}
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list, binary or range".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
},
|
||||
PipelineData::ListStream(mut ls, metadata) => {
|
||||
|
@ -175,11 +175,8 @@ enum TableInside<'a> {
|
||||
},
|
||||
}
|
||||
|
||||
fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) -> Vec<Value> {
|
||||
let tag = match item.span() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return vec![Value::Error { error: Box::new(e) }],
|
||||
};
|
||||
fn flat_value(columns: &[CellPath], item: &Value, name_tag: Span, all: bool) -> Vec<Value> {
|
||||
let tag = item.span();
|
||||
|
||||
if item.as_record().is_ok() {
|
||||
let mut out = IndexMap::<String, Value>::new();
|
||||
@ -194,17 +191,15 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
error: Box::new(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: _name_tag,
|
||||
src_span: other.expect_span(),
|
||||
dst_span: name_tag,
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: name_tag,
|
||||
}];
|
||||
}
|
||||
};
|
||||
|
||||
let s = match item.span() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return vec![Value::Error { error: Box::new(e) }],
|
||||
};
|
||||
let s = item.span();
|
||||
|
||||
for (column_index, (column, value)) in record.iter().enumerate() {
|
||||
let column_requested = columns.iter().find(|c| c.into_string() == *column);
|
||||
@ -233,7 +228,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
"value originates from here".into(),
|
||||
s,
|
||||
*span
|
||||
))}
|
||||
)), span: *span}
|
||||
];
|
||||
}
|
||||
// it's a table (a list of record, we can flatten inner record)
|
||||
@ -269,7 +264,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
"value originates from here".into(),
|
||||
s,
|
||||
*span
|
||||
))}
|
||||
)), span: *span}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ fn replace_headers(
|
||||
}
|
||||
_ => Err(ShellError::TypeMismatch {
|
||||
err_message: "record".to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -148,7 +148,7 @@ fn extract_headers(
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "needs compatible type: Null, String, Bool, Float, Int"
|
||||
.to_string(),
|
||||
span: v.span()?,
|
||||
span: v.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ fn extract_headers(
|
||||
})?,
|
||||
_ => Err(ShellError::TypeMismatch {
|
||||
err_message: "record".to_string(),
|
||||
span: value.span()?,
|
||||
span: value.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -173,12 +173,18 @@ fn insert(
|
||||
pd.into_value(span),
|
||||
span,
|
||||
) {
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
}
|
||||
Err(e) => Value::Error { error: Box::new(e) },
|
||||
Err(e) => Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
},
|
||||
}
|
||||
},
|
||||
ctrlc,
|
||||
@ -209,7 +215,10 @@ fn insert(
|
||||
if let Err(e) =
|
||||
input.insert_data_at_cell_path(&cell_path.members, replacement, span)
|
||||
{
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
|
@ -1,4 +1,3 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{eval_block_with_early_return, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
|
||||
@ -7,6 +6,8 @@ use nu_protocol::{
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use super::utils::chain_error_with_input;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Items;
|
||||
|
||||
@ -85,9 +86,10 @@ impl Command for Items {
|
||||
Ok(v) => Some(v.into_value(span)),
|
||||
Err(ShellError::Break(_)) => None,
|
||||
Err(error) => {
|
||||
let error = chain_error_with_input(error, Ok(input_span));
|
||||
let error = chain_error_with_input(error, false, input_span);
|
||||
Some(Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -105,12 +107,12 @@ impl Command for Items {
|
||||
dst_span: call.head,
|
||||
src_span: input_span,
|
||||
}),
|
||||
PipelineData::Value(Value::Error { error }, ..) => Err(*error),
|
||||
PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error),
|
||||
PipelineData::Value(other, ..) => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
PipelineData::ExternalStream { .. } => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record".into(),
|
||||
|
@ -170,12 +170,12 @@ impl Command for Last {
|
||||
}
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list, binary or range".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
},
|
||||
PipelineData::ExternalStream { span, .. } => {
|
||||
|
@ -74,7 +74,7 @@ fn length_row(call: &Call, input: PipelineData) -> Result<PipelineData, ShellErr
|
||||
let mut count: i64 = 0;
|
||||
// Check for and propagate errors
|
||||
for value in input.into_iter() {
|
||||
if let Value::Error { error } = value {
|
||||
if let Value::Error { error, .. } = value {
|
||||
return Err(*error);
|
||||
}
|
||||
count += 1
|
||||
|
@ -112,12 +112,12 @@ impl Command for Lines {
|
||||
PipelineData::Value(val, ..) => {
|
||||
match val {
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
_ => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string or raw data".into(),
|
||||
wrong_type: val.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: val.expect_span(),
|
||||
src_span: val.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -131,6 +131,7 @@ impl Command for Lines {
|
||||
Ok(x) => x,
|
||||
Err(err) => Value::Error {
|
||||
error: Box::new(err),
|
||||
span: head,
|
||||
},
|
||||
})
|
||||
.into_pipeline_data(ctrlc)),
|
||||
@ -234,13 +235,13 @@ impl Iterator for RawStreamLinesAdapter {
|
||||
self.queue.append(&mut lines);
|
||||
}
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => return Some(Err(*error)),
|
||||
Value::Error { error, .. } => return Some(Err(*error)),
|
||||
other => {
|
||||
return Some(Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: self.span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -115,11 +115,13 @@ repeating this process with row 1, and so on."#
|
||||
Ok(to_merge) => Value::record(do_merge(inp, to_merge), call.head),
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: call.head,
|
||||
},
|
||||
},
|
||||
(_, None) => inp,
|
||||
(Err(error), _) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: call.head,
|
||||
},
|
||||
});
|
||||
|
||||
@ -137,10 +139,10 @@ repeating this process with row 1, and so on."#
|
||||
(PipelineData::Value(val, ..), ..) => {
|
||||
// Only point the "value originates here" arrow at the merge value
|
||||
// if it was generated from a block. Otherwise, point at the pipeline value. -Leon 2022-10-27
|
||||
let span = if val.span()? == Span::test_data() {
|
||||
let span = if val.span() == Span::test_data() {
|
||||
Span::new(call.head.start, call.head.start)
|
||||
} else {
|
||||
val.span()?
|
||||
val.span()
|
||||
};
|
||||
|
||||
Err(ShellError::PipelineMismatch {
|
||||
|
@ -117,11 +117,11 @@ impl Command for Move {
|
||||
let before_or_after = match (after, before) {
|
||||
(Some(v), None) => Spanned {
|
||||
item: BeforeOrAfter::After(v.as_string()?),
|
||||
span: v.span()?,
|
||||
span: v.span(),
|
||||
},
|
||||
(None, Some(v)) => Spanned {
|
||||
item: BeforeOrAfter::Before(v.as_string()?),
|
||||
span: v.span()?,
|
||||
span: v.span(),
|
||||
},
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(ShellError::GenericError(
|
||||
@ -155,11 +155,13 @@ impl Command for Move {
|
||||
Ok(val) => val,
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: call.head,
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: call.head,
|
||||
},
|
||||
});
|
||||
|
||||
@ -233,7 +235,7 @@ fn move_record_columns(
|
||||
return Err(ShellError::GenericError(
|
||||
"Cannot move columns".to_string(),
|
||||
"column does not exist".to_string(),
|
||||
Some(column.span()?),
|
||||
Some(column.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
|
@ -142,6 +142,8 @@ impl Command for ParEach {
|
||||
}
|
||||
|
||||
let val_span = x.span();
|
||||
let x_is_error = x.is_error();
|
||||
|
||||
match eval_block_with_early_return(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
@ -153,7 +155,10 @@ impl Command for ParEach {
|
||||
Ok(v) => v.into_value(span),
|
||||
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, val_span)),
|
||||
error: Box::new(chain_error_with_input(
|
||||
error, x_is_error, val_span,
|
||||
)),
|
||||
span: val_span,
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -176,6 +181,8 @@ impl Command for ParEach {
|
||||
}
|
||||
|
||||
let val_span = x.span();
|
||||
let x_is_error = x.is_error();
|
||||
|
||||
match eval_block_with_early_return(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
@ -186,7 +193,10 @@ impl Command for ParEach {
|
||||
) {
|
||||
Ok(v) => v.into_value(span),
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, val_span)),
|
||||
error: Box::new(chain_error_with_input(
|
||||
error, x_is_error, val_span,
|
||||
)),
|
||||
span: val_span,
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -209,6 +219,8 @@ impl Command for ParEach {
|
||||
}
|
||||
|
||||
let val_span = x.span();
|
||||
let x_is_error = x.is_error();
|
||||
|
||||
match eval_block_with_early_return(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
@ -219,7 +231,10 @@ impl Command for ParEach {
|
||||
) {
|
||||
Ok(v) => v.into_value(span),
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(chain_error_with_input(error, val_span)),
|
||||
error: Box::new(chain_error_with_input(
|
||||
error, x_is_error, val_span,
|
||||
)),
|
||||
span: val_span,
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -240,6 +255,7 @@ impl Command for ParEach {
|
||||
Err(err) => {
|
||||
return Value::Error {
|
||||
error: Box::new(err),
|
||||
span,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -265,6 +281,7 @@ impl Command for ParEach {
|
||||
Ok(v) => v.into_value(span),
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ fn rename(
|
||||
return Err(ShellError::TypeMismatch { err_message: "The column list cannot be empty and must contain only two values: the column's name and its replacement value"
|
||||
.to_string(), span: column_span });
|
||||
} else {
|
||||
(Some(columns[0].span()?), column_span)
|
||||
(Some(columns[0].span()), column_span)
|
||||
}
|
||||
} else {
|
||||
(None, call.head)
|
||||
@ -180,9 +180,19 @@ fn rename(
|
||||
redirect_stderr,
|
||||
);
|
||||
match eval_result {
|
||||
Err(e) => return Value::Error { error: Box::new(e) },
|
||||
Err(e) => {
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
}
|
||||
}
|
||||
Ok(res) => match res.collect_string_strict(span) {
|
||||
Err(e) => return Value::Error { error: Box::new(e) },
|
||||
Err(e) => {
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
}
|
||||
}
|
||||
Ok(new_c) => *c = new_c.0,
|
||||
},
|
||||
}
|
||||
@ -204,6 +214,7 @@ fn rename(
|
||||
// Arrow 2 points at the input value.
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
};
|
||||
}
|
||||
for (idx, val) in record.cols.iter_mut().enumerate() {
|
||||
@ -234,8 +245,9 @@ fn rename(
|
||||
exp_input_type: "record".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head_span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span: head_span,
|
||||
},
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
|
@ -64,14 +64,14 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
let columns: Vec<Value> = call.rest(engine_state, stack, 0)?;
|
||||
let mut new_columns: Vec<CellPath> = vec![];
|
||||
for col_val in columns {
|
||||
let col_span = &col_val.span()?;
|
||||
let col_span = &col_val.span();
|
||||
match col_val {
|
||||
Value::CellPath { val, .. } => {
|
||||
new_columns.push(val);
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
for value in vals {
|
||||
let val_span = &value.span()?;
|
||||
let val_span = &value.span();
|
||||
match value {
|
||||
Value::String { val, .. } => {
|
||||
let cv = CellPath {
|
||||
@ -97,7 +97,7 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "cell path".into(),
|
||||
from_type: y.get_type().to_string(),
|
||||
span: y.span()?,
|
||||
span: y.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
@ -128,7 +128,7 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "cell path".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ pub fn split(
|
||||
None => Err(ShellError::CantFindColumn {
|
||||
col_name: column_name.item.to_string(),
|
||||
span: column_name.span,
|
||||
src_span: row.span().unwrap_or(column_name.span),
|
||||
src_span: row.span(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
@ -73,12 +73,12 @@ impl Command for Take {
|
||||
.into_pipeline_data(ctrlc)
|
||||
.set_metadata(metadata)),
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list, binary or range".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
},
|
||||
PipelineData::ListStream(ls, metadata) => Ok(ls
|
||||
|
@ -271,7 +271,7 @@ pub fn transpose(
|
||||
}
|
||||
v => Value::List {
|
||||
vals: vec![v.clone(), x.clone()],
|
||||
span: v.expect_span(),
|
||||
span: v.span(),
|
||||
},
|
||||
};
|
||||
record.cols.remove(index);
|
||||
@ -309,7 +309,7 @@ pub fn transpose(
|
||||
}
|
||||
v => Value::List {
|
||||
vals: vec![v.clone(), Value::nothing(name)],
|
||||
span: v.expect_span(),
|
||||
span: v.span(),
|
||||
},
|
||||
};
|
||||
record.cols.remove(index);
|
||||
|
@ -140,7 +140,12 @@ fn update(
|
||||
|
||||
let input_at_path = match input.clone().follow_cell_path(&cell_path.members, false)
|
||||
{
|
||||
Err(e) => return Value::Error { error: Box::new(e) },
|
||||
Err(e) => {
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
}
|
||||
}
|
||||
Ok(v) => v,
|
||||
};
|
||||
let output = eval_block(
|
||||
@ -157,12 +162,18 @@ fn update(
|
||||
if let Err(e) =
|
||||
input.update_data_at_cell_path(&cell_path.members, pd.into_value(span))
|
||||
{
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
}
|
||||
Err(e) => Value::Error { error: Box::new(e) },
|
||||
Err(e) => Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
},
|
||||
}
|
||||
},
|
||||
ctrlc,
|
||||
@ -199,7 +210,10 @@ fn update(
|
||||
let replacement = replacement.clone();
|
||||
|
||||
if let Err(e) = input.update_data_at_cell_path(&cell_path.members, replacement) {
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
|
@ -178,12 +178,18 @@ fn upsert(
|
||||
if let Err(e) =
|
||||
input.upsert_data_at_cell_path(&cell_path.members, pd.into_value(span))
|
||||
{
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
}
|
||||
Err(e) => Value::Error { error: Box::new(e) },
|
||||
Err(e) => Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
},
|
||||
}
|
||||
},
|
||||
ctrlc,
|
||||
@ -219,7 +225,10 @@ fn upsert(
|
||||
let replacement = replacement.clone();
|
||||
|
||||
if let Err(e) = input.upsert_data_at_cell_path(&cell_path.members, replacement) {
|
||||
return Value::Error { error: Box::new(e) };
|
||||
return Value::Error {
|
||||
error: Box::new(e),
|
||||
span,
|
||||
};
|
||||
}
|
||||
|
||||
input
|
||||
|
@ -7,9 +7,10 @@ use nu_protocol::{
|
||||
|
||||
pub fn chain_error_with_input(
|
||||
error_source: ShellError,
|
||||
input_span: Result<Span, ShellError>,
|
||||
input_is_error: bool,
|
||||
span: Span,
|
||||
) -> ShellError {
|
||||
if let Ok(span) = input_span {
|
||||
if !input_is_error {
|
||||
return ShellError::EvalBlockWithInput(span, vec![error_source]);
|
||||
}
|
||||
error_source
|
||||
|
@ -119,7 +119,7 @@ pub fn get_values<'a>(
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
_ => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".into(),
|
||||
@ -176,12 +176,12 @@ fn values(
|
||||
Ok(val.vals.into_pipeline_data(ctrlc).set_metadata(metadata))
|
||||
}
|
||||
// Propagate errors
|
||||
PipelineData::Value(Value::Error { error }, ..) => Err(*error),
|
||||
PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error),
|
||||
PipelineData::Value(other, ..) => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
PipelineData::ExternalStream { .. } => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".into(),
|
||||
|
@ -101,6 +101,7 @@ not supported."#
|
||||
}
|
||||
Err(err) => Some(Value::Error {
|
||||
error: Box::new(err),
|
||||
span,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
@ -77,6 +77,7 @@ impl Command for FromJson {
|
||||
Ok(v) => Some(v),
|
||||
Err(error) => Some(Value::Error {
|
||||
error: Box::new(error),
|
||||
span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -120,6 +121,7 @@ fn convert_nujson_to_value(value: &nu_json::Value, span: Span) -> Value {
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
} else {
|
||||
Value::Int {
|
||||
|
@ -45,7 +45,7 @@ impl Command for FromOds {
|
||||
let sel_sheets = if let Some(Value::List { vals: columns, .. }) =
|
||||
call.get_flag(engine_state, stack, "sheets")?
|
||||
{
|
||||
convert_columns(columns.as_slice(), call.head)?
|
||||
convert_columns(columns.as_slice())?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
@ -69,14 +69,14 @@ impl Command for FromOds {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_columns(columns: &[Value], span: Span) -> Result<Vec<String>, ShellError> {
|
||||
fn convert_columns(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>, _>>()?;
|
||||
@ -93,13 +93,13 @@ fn collect_binary(input: PipelineData, span: Span) -> Result<Vec<u8>, ShellError
|
||||
Some(Value::Binary { val: b, .. }) => {
|
||||
bytes.extend_from_slice(&b);
|
||||
}
|
||||
Some(Value::Error { error }) => return Err(*error),
|
||||
Some(Value::Error { error, .. }) => return Err(*error),
|
||||
Some(x) => {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Expected binary from pipeline".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
x.expect_span(),
|
||||
x.span(),
|
||||
))
|
||||
}
|
||||
None => break,
|
||||
|
@ -45,7 +45,7 @@ impl Command for FromXlsx {
|
||||
let sel_sheets = if let Some(Value::List { vals: columns, .. }) =
|
||||
call.get_flag(engine_state, stack, "sheets")?
|
||||
{
|
||||
convert_columns(columns.as_slice(), call.head)?
|
||||
convert_columns(columns.as_slice())?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
@ -69,14 +69,14 @@ impl Command for FromXlsx {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_columns(columns: &[Value], span: Span) -> Result<Vec<String>, ShellError> {
|
||||
fn convert_columns(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>, _>>()?;
|
||||
@ -98,7 +98,7 @@ fn collect_binary(input: PipelineData, span: Span) -> Result<Vec<u8>, ShellError
|
||||
"Expected binary from pipeline".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
x.expect_span(),
|
||||
x.span(),
|
||||
))
|
||||
}
|
||||
None => break,
|
||||
|
@ -14,8 +14,8 @@ fn from_value_to_delimited_string(
|
||||
Value::Record { val, span } => record_to_delimited(val, *span, separator, config, head),
|
||||
Value::List { vals, span } => table_to_delimited(vals, *span, separator, config, head),
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
v => Err(make_unsupported_input_error(v, head, v.expect_span())),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
v => Err(make_unsupported_input_error(v, head, v.span())),
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ fn to_string_tagged_value(
|
||||
Value::Date { val, .. } => Ok(val.to_string()),
|
||||
Value::Nothing { .. } => Ok(String::new()),
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
_ => Err(make_unsupported_input_error(v, head, span)),
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,7 @@ pub fn to_delimited_data(
|
||||
Err(_) => Err(ShellError::CantConvert {
|
||||
to_type: format_name.into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span().unwrap_or(span),
|
||||
span: value.span(),
|
||||
help: None,
|
||||
}),
|
||||
}?;
|
||||
|
@ -76,6 +76,7 @@ impl Command for ToJson {
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
@ -126,7 +127,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
|
||||
),
|
||||
|
||||
Value::List { vals, .. } => nu_json::Value::Array(json_list(vals)?),
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
Value::Closure { .. }
|
||||
| Value::Block { .. }
|
||||
| Value::Range { .. }
|
||||
|
@ -85,6 +85,7 @@ impl Command for ToNuon {
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
@ -136,7 +137,7 @@ pub fn value_to_string(
|
||||
"could not convert binary to string".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -146,13 +147,13 @@ pub fn value_to_string(
|
||||
"blocks are currently not nuon-compatible".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
Value::Closure { .. } => Err(ShellError::UnsupportedInput(
|
||||
"closures are currently not nuon-compatible".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
Value::Bool { val, .. } => {
|
||||
if *val {
|
||||
@ -165,19 +166,19 @@ pub fn value_to_string(
|
||||
"cellpaths are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput(
|
||||
"custom values are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
Value::Date { val, .. } => Ok(val.to_rfc3339()),
|
||||
// FIXME: make durations use the shortest lossless representation.
|
||||
Value::Duration { val, .. } => Ok(format!("{}ns", *val)),
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
// FIXME: make filesizes use the shortest lossless representation.
|
||||
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
||||
Value::Float { val, .. } => {
|
||||
@ -246,7 +247,7 @@ pub fn value_to_string(
|
||||
"match patterns are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
Value::Nothing { .. } => Ok("null".to_string()),
|
||||
Value::Range { val, .. } => Ok(format!(
|
||||
|
@ -148,7 +148,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> 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(),
|
||||
|
@ -77,7 +77,7 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
|
||||
toml::Value::String(code)
|
||||
}
|
||||
Value::Nothing { .. } => toml::Value::String("<Nothing>".to_string()),
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
Value::Binary { val, .. } => toml::Value::Array(
|
||||
val.iter()
|
||||
.map(|x| toml::Value::Integer(*x as i64))
|
||||
@ -125,6 +125,7 @@ fn toml_into_pipeline_data(
|
||||
span,
|
||||
help: None,
|
||||
}),
|
||||
span,
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
@ -138,12 +139,12 @@ fn value_to_toml_value(
|
||||
match v {
|
||||
Value::Record { .. } => helper(engine_state, v),
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
format!("{:?} is not valid top-level TOML", v.get_type()),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
v.expect_span(),
|
||||
v.span(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ fn to_xml_entry<W: Write>(
|
||||
top_level: bool,
|
||||
writer: &mut quick_xml::Writer<W>,
|
||||
) -> Result<(), ShellError> {
|
||||
let entry_span = entry.span()?;
|
||||
let entry_span = entry.span();
|
||||
|
||||
// Allow using strings directly as content.
|
||||
// So user can write
|
||||
@ -197,7 +197,7 @@ fn to_tag_like<W: Write>(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "XML".into(),
|
||||
from_type: Type::Record(vec![]).to_string(),
|
||||
span: content.span()?,
|
||||
span: content.span(),
|
||||
help: Some("PI content expected to be a string".into()),
|
||||
});
|
||||
}
|
||||
@ -215,7 +215,7 @@ fn to_tag_like<W: Write>(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "XML".into(),
|
||||
from_type: attrs.get_type().to_string(),
|
||||
span: attrs.span()?,
|
||||
span: attrs.span(),
|
||||
help: Some("Tag attributes expected to be a record".into()),
|
||||
});
|
||||
}
|
||||
@ -228,7 +228,7 @@ fn to_tag_like<W: Write>(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "XML".into(),
|
||||
from_type: content.get_type().to_string(),
|
||||
span: content.span()?,
|
||||
span: content.span(),
|
||||
help: Some("Tag content expected to be a list".into()),
|
||||
});
|
||||
}
|
||||
@ -350,7 +350,7 @@ fn parse_attributes(attrs: Record) -> Result<IndexMap<String, String>, ShellErro
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "XML".to_string(),
|
||||
from_type: v.get_type().to_string(),
|
||||
span: v.span()?,
|
||||
span: v.span(),
|
||||
help: Some("Attribute value expected to be a string".into()),
|
||||
});
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
|
||||
Value::Block { .. } => serde_yaml::Value::Null,
|
||||
Value::Closure { .. } => serde_yaml::Value::Null,
|
||||
Value::Nothing { .. } => serde_yaml::Value::Null,
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
Value::Binary { val, .. } => serde_yaml::Value::Sequence(
|
||||
val.iter()
|
||||
.map(|x| serde_yaml::Value::Number(serde_yaml::Number::from(*x)))
|
||||
@ -118,6 +118,7 @@ fn to_yaml(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
|
||||
span: head,
|
||||
help: None,
|
||||
}),
|
||||
span: head,
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ pub fn run_seq_dates(
|
||||
return Err(ShellError::GenericError(
|
||||
"increment cannot be 0".to_string(),
|
||||
"increment cannot be 0".to_string(),
|
||||
Some(increment.span()?),
|
||||
Some(increment.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
|
@ -112,8 +112,9 @@ where
|
||||
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());
|
||||
}
|
||||
@ -157,22 +158,16 @@ where
|
||||
// Propagate existing errors
|
||||
Value::Error { .. } => return input.clone(),
|
||||
other => {
|
||||
let span = match input.span() {
|
||||
Ok(span) => span,
|
||||
Err(error) => {
|
||||
return Value::Error {
|
||||
error: Box::new(error),
|
||||
}
|
||||
}
|
||||
};
|
||||
let span = input.span();
|
||||
|
||||
return Value::Error {
|
||||
error: Box::new(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string or binary".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
src_span: other.span(),
|
||||
}),
|
||||
span,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -154,7 +154,7 @@ pub fn highlight_search_in_table(
|
||||
return Err(ShellError::NushellFailedSpanned {
|
||||
msg: "Expected record".to_string(),
|
||||
label: format!("got {}", record.get_type()),
|
||||
span: record.span()?,
|
||||
span: record.span(),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub fn eval_env_change_hook(
|
||||
x => {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "record for the 'env_change' hook".to_string(),
|
||||
span: x.span()?,
|
||||
span: x.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ pub fn eval_hook(
|
||||
arguments: Vec<(String, Value)>,
|
||||
value: &Value,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let value_span = value.span()?;
|
||||
let value_span = value.span();
|
||||
|
||||
// Hooks can optionally be a record in this form:
|
||||
// {
|
||||
@ -92,7 +92,7 @@ pub fn eval_hook(
|
||||
for (name, val) in arguments {
|
||||
let var_id = working_set.add_variable(
|
||||
name.as_bytes().to_vec(),
|
||||
val.span()?,
|
||||
val.span(),
|
||||
Type::Any,
|
||||
false,
|
||||
);
|
||||
@ -191,7 +191,7 @@ pub fn eval_hook(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"block".to_string(),
|
||||
format!("{}", other.get_type()),
|
||||
other.span()?,
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -214,7 +214,7 @@ pub fn eval_hook(
|
||||
for (name, val) in arguments {
|
||||
let var_id = working_set.add_variable(
|
||||
name.as_bytes().to_vec(),
|
||||
val.span()?,
|
||||
val.span(),
|
||||
Type::Any,
|
||||
false,
|
||||
);
|
||||
@ -293,7 +293,7 @@ pub fn eval_hook(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"block or string".to_string(),
|
||||
format!("{}", other.get_type()),
|
||||
other.span()?,
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -331,7 +331,7 @@ pub fn eval_hook(
|
||||
return Err(ShellError::UnsupportedConfigValue(
|
||||
"string, block, record, or list of commands".into(),
|
||||
format!("{}", other.get_type()),
|
||||
other.span()?,
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -374,7 +374,7 @@ fn run_hook_block(
|
||||
let pipeline_data =
|
||||
eval_block_with_early_return(engine_state, &mut callee_stack, block, input, false, false)?;
|
||||
|
||||
if let PipelineData::Value(Value::Error { error }, _) = pipeline_data {
|
||||
if let PipelineData::Value(Value::Error { error, .. }, _) = pipeline_data {
|
||||
return Err(*error);
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,9 @@ fn abs_helper(val: 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ fn operate(value: Value, head: Span, base: f64) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
};
|
||||
}
|
||||
// Specialize for better precision/performance
|
||||
@ -128,8 +129,9 @@ fn operate(value: Value, head: Span, base: f64) -> 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,9 +90,9 @@ pub fn median(values: &[Value], span: Span, head: Span) -> Result<Value, ShellEr
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: head,
|
||||
lhs_ty: elem[0].get_type().to_string(),
|
||||
lhs_span: elem[0].span()?,
|
||||
lhs_span: elem[0].span(),
|
||||
rhs_ty: elem[1].get_type().to_string(),
|
||||
rhs_span: elem[1].span()?,
|
||||
rhs_span: elem[1].span(),
|
||||
});
|
||||
}
|
||||
Ok(elem[0].partial_cmp(&elem[1]).unwrap_or(Ordering::Equal))
|
||||
|
@ -116,9 +116,9 @@ pub fn mode(values: &[Value], _span: Span, head: Span) -> Result<Value, ShellErr
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: head,
|
||||
lhs_ty: elem[0].get_type().to_string(),
|
||||
lhs_span: elem[0].span()?,
|
||||
lhs_span: elem[0].span(),
|
||||
rhs_ty: elem[1].get_type().to_string(),
|
||||
rhs_span: elem[1].span()?,
|
||||
rhs_span: elem[1].span(),
|
||||
});
|
||||
}
|
||||
Ok(elem[0].partial_cmp(&elem[1]).unwrap_or(Ordering::Equal))
|
||||
@ -143,12 +143,12 @@ pub fn mode(values: &[Value], _span: Span, head: Span) -> Result<Value, ShellErr
|
||||
Value::Filesize { val, .. } => {
|
||||
Ok(HashableType::new(val.to_ne_bytes(), NumberTypes::Filesize))
|
||||
}
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
other => Err(ShellError::UnsupportedInput(
|
||||
"Unable to give a result with this input".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
)),
|
||||
})
|
||||
.collect::<Result<Vec<HashableType>, ShellError>>()?;
|
||||
|
@ -42,9 +42,9 @@ pub fn max(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: head,
|
||||
lhs_ty: biggest.get_type().to_string(),
|
||||
lhs_span: biggest.span()?,
|
||||
lhs_span: biggest.span(),
|
||||
rhs_ty: value.get_type().to_string(),
|
||||
rhs_span: value.span()?,
|
||||
rhs_span: value.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -73,9 +73,9 @@ pub fn min(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: head,
|
||||
lhs_ty: smallest.get_type().to_string(),
|
||||
lhs_span: smallest.span()?,
|
||||
lhs_span: smallest.span(),
|
||||
rhs_ty: value.get_type().to_string(),
|
||||
rhs_span: value.span()?,
|
||||
rhs_span: value.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -112,13 +112,13 @@ pub fn sum(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError
|
||||
| Value::Duration { .. } => {
|
||||
acc = acc.add(head, value, head)?;
|
||||
}
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
other => {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Attempted to compute the sum of a value that cannot be summed".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -145,14 +145,14 @@ pub fn product(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellE
|
||||
Value::Int { .. } | Value::Float { .. } => {
|
||||
acc = acc.mul(head, value, head)?;
|
||||
}
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
other => {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Attempted to compute the product of a value that cannot be multiplied"
|
||||
.to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -126,8 +126,9 @@ fn operate(value: Value, head: Span, precision: Option<i64>) -> 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -83,8 +83,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,6 +98,7 @@ fn error_negative_sqrt(head: Span, span: Span) -> Value {
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
span,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,10 @@ fn helper_for_tables(
|
||||
.or_insert_with(|| vec![value.clone()]);
|
||||
}
|
||||
}
|
||||
Value::Error { error } => return Err(*error.clone()),
|
||||
Value::Error { error, .. } => return Err(*error.clone()),
|
||||
_ => {
|
||||
//Turns out we are not dealing with a table
|
||||
return mf(values, val.expect_span(), name);
|
||||
return mf(values, val.span(), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,13 +64,13 @@ fn sum_of_squares(values: &[Value], span: Span) -> Result<Value, ShellError> {
|
||||
for value in values {
|
||||
let v = match &value {
|
||||
Value::Int { .. } | Value::Float { .. } => Ok(value),
|
||||
Value::Error { error } => Err(*error.clone()),
|
||||
Value::Error { error, .. } => Err(*error.clone()),
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"Attempted to compute the sum of squares of a non-integer, non-float value"
|
||||
.to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
value.expect_span(),
|
||||
value.span(),
|
||||
)),
|
||||
}?;
|
||||
let v_squared = &v.mul(span, v, span)?;
|
||||
|
@ -278,7 +278,7 @@ pub fn request_set_timeout(
|
||||
if val.is_negative() || val < 1 {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "Timeout value must be an integer and larger than 0".to_string(),
|
||||
span: timeout.expect_span(),
|
||||
span: timeout.span(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ pub fn request_add_custom_headers(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
span: headers.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
@ -335,7 +335,7 @@ pub fn request_add_custom_headers(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
span: headers.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -167,7 +167,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -141,7 +141,7 @@ fn helper(
|
||||
args: Arguments,
|
||||
ctrlc: Option<Arc<AtomicBool>>,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
let client = http_client(args.insecure);
|
||||
|
@ -156,7 +156,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -94,12 +94,12 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
|
||||
}
|
||||
}
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::UnsupportedInput(
|
||||
"Expected a table from pipeline".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
)),
|
||||
})
|
||||
.collect();
|
||||
|
@ -109,8 +109,9 @@ fn action_all(input: &Value, _arg: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -130,8 +131,9 @@ fn action(input: &Value, _arg: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user