forked from extern/nushell
Document and critically review ShellError
variants - Ep. 3 (#8340)
Continuation of #8229 and #8326 # Description The `ShellError` enum at the moment is kind of messy. Many variants are basic tuple structs where you always have to reference the implementation with its macro invocation to know which field serves which purpose. Furthermore we have both variants that are kind of redundant or either overly broad to be useful for the user to match on or overly specific with few uses. So I set out to start fixing the lacking documentation and naming to make it feasible to critically review the individual usages and fix those. Furthermore we can decide to join or split up variants that don't seem to be fit for purpose. # Call to action **Everyone:** Feel free to add review comments if you spot inconsistent use of `ShellError` variants. # User-Facing Changes (None now, end goal more explicit and consistent error messages) # Tests + Formatting (No additional tests needed so far) # Commits (so far) - Remove `ShellError::FeatureNotEnabled` - Name fields on `SE::ExternalNotSupported` - Name field on `SE::InvalidProbability` - Name fields on `SE::NushellFailed` variants - Remove unused `SE::NushellFailedSpannedHelp` - Name field on `SE::VariableNotFoundAtRuntime` - Name fields on `SE::EnvVarNotFoundAtRuntime` - Name fields on `SE::ModuleNotFoundAtRuntime` - Remove usused `ModuleOrOverlayNotFoundAtRuntime` - Name fields on `SE::OverlayNotFoundAtRuntime` - Name field on `SE::NotFound`
This commit is contained in:
committed by
GitHub
parent
4898750fc1
commit
62575c9a4f
@ -204,11 +204,11 @@ fn run_histogram(
|
||||
}
|
||||
|
||||
if inputs.is_empty() {
|
||||
return Err(ShellError::CantFindColumn(
|
||||
col_name.clone(),
|
||||
head_span,
|
||||
list_span,
|
||||
));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: col_name.clone(),
|
||||
span: head_span,
|
||||
src_span: list_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,15 +134,15 @@ fn string_to_boolean(s: &str, span: Span) -> Result<bool, ShellError> {
|
||||
let val = o.parse::<f64>();
|
||||
match val {
|
||||
Ok(f) => Ok(f.abs() >= f64::EPSILON),
|
||||
Err(_) => Err(ShellError::CantConvert(
|
||||
"boolean".to_string(),
|
||||
"string".to_string(),
|
||||
Err(_) => Err(ShellError::CantConvert {
|
||||
to_type: "boolean".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
Some(
|
||||
help: Some(
|
||||
r#"the strings "true" and "false" can be converted into a bool"#
|
||||
.to_string(),
|
||||
),
|
||||
)),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,12 +307,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
Ok(d) => Value::Date { val: d, span: head },
|
||||
Err(reason) => {
|
||||
Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
format!("could not parse as datetime using format '{}'", dt.0),
|
||||
reason.to_string(),
|
||||
head,
|
||||
Some("you can use `into datetime` without a format string to enable flexible parsing".to_string())
|
||||
),
|
||||
error: 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()) },
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -88,12 +88,12 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
match other.parse::<f64>() {
|
||||
Ok(x) => Value::float(x, head),
|
||||
Err(reason) => Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"float".to_string(),
|
||||
reason.to_string(),
|
||||
*span,
|
||||
None,
|
||||
),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "float".to_string(),
|
||||
from_type: reason.to_string(),
|
||||
span: *span,
|
||||
help: None,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -315,17 +315,17 @@ fn convert_str_from_unit_to_unit(
|
||||
("yr", "yr") => Ok(val as f64),
|
||||
("yr", "dec") => Ok(val as f64 / 10.0),
|
||||
|
||||
_ => Err(ShellError::CantConvertWithValue(
|
||||
"string duration".to_string(),
|
||||
"string duration".to_string(),
|
||||
to_unit.to_string(),
|
||||
span,
|
||||
value_span,
|
||||
Some(
|
||||
_ => Err(ShellError::CantConvertWithValue {
|
||||
to_type: "string duration".to_string(),
|
||||
from_type: "string duration".to_string(),
|
||||
details: to_unit.to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
help: Some(
|
||||
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec"
|
||||
.to_string(),
|
||||
),
|
||||
)),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,16 +348,16 @@ fn string_to_duration(s: &str, span: Span, value_span: Span) -> Result<i64, Shel
|
||||
}
|
||||
}
|
||||
|
||||
Err(ShellError::CantConvertWithValue(
|
||||
"duration".to_string(),
|
||||
"string".to_string(),
|
||||
s.to_string(),
|
||||
span,
|
||||
value_span,
|
||||
Some(
|
||||
Err(ShellError::CantConvertWithValue {
|
||||
to_type: "duration".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
details: s.to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
help: Some(
|
||||
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec".to_string(),
|
||||
),
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
fn string_to_unit_duration(
|
||||
@ -384,16 +384,16 @@ fn string_to_unit_duration(
|
||||
}
|
||||
}
|
||||
|
||||
Err(ShellError::CantConvertWithValue(
|
||||
"duration".to_string(),
|
||||
"string".to_string(),
|
||||
s.to_string(),
|
||||
span,
|
||||
value_span,
|
||||
Some(
|
||||
Err(ShellError::CantConvertWithValue {
|
||||
to_type: "duration".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
details: s.to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
help: Some(
|
||||
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec".to_string(),
|
||||
),
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
fn action(
|
||||
@ -468,12 +468,12 @@ fn action(
|
||||
}
|
||||
} else {
|
||||
Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"duration".into(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: "duration".into(),
|
||||
span,
|
||||
None,
|
||||
),
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -133,12 +133,12 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
match a_string.trim().parse::<bytesize::ByteSize>() {
|
||||
Ok(n) => Ok(n.0 as i64),
|
||||
Err(_) => Err(ShellError::CantConvert(
|
||||
"int".into(),
|
||||
"string".into(),
|
||||
Err(_) => Err(ShellError::CantConvert {
|
||||
to_type: "int".into(),
|
||||
from_type: "string".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,12 +187,12 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
Ok(v) => v,
|
||||
_ => {
|
||||
return Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"float".to_string(),
|
||||
"integer".to_string(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "float".to_string(),
|
||||
from_type: "integer".to_string(),
|
||||
span,
|
||||
None,
|
||||
),
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,12 +277,12 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
Ok(n) => return Value::int(n, head),
|
||||
Err(e) => {
|
||||
return Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"string".to_string(),
|
||||
"int".to_string(),
|
||||
head,
|
||||
Some(e.to_string()),
|
||||
),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "string".to_string(),
|
||||
from_type: "int".to_string(),
|
||||
span: head,
|
||||
help: Some(e.to_string()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -305,7 +305,12 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
match i64::from_str_radix(i.trim(), radix) {
|
||||
Ok(n) => Value::int(n, head),
|
||||
Err(_reason) => Value::Error {
|
||||
error: ShellError::CantConvert("string".to_string(), "int".to_string(), head, None),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "string".to_string(),
|
||||
from_type: "int".to_string(),
|
||||
span: head,
|
||||
help: None,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -317,12 +322,12 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
let num = match i64::from_str_radix(b.trim_start_matches("0b"), 2) {
|
||||
Ok(n) => n,
|
||||
Err(_reason) => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"int".to_string(),
|
||||
"string".to_string(),
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "int".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
Some(r#"digits following "0b" can only be 0 or 1"#.to_string()),
|
||||
))
|
||||
help: Some(r#"digits following "0b" can only be 0 or 1"#.to_string()),
|
||||
})
|
||||
}
|
||||
};
|
||||
Ok(num)
|
||||
@ -331,15 +336,15 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
let num =
|
||||
match i64::from_str_radix(h.trim_start_matches("0x"), 16) {
|
||||
Ok(n) => n,
|
||||
Err(_reason) => return Err(ShellError::CantConvert(
|
||||
"int".to_string(),
|
||||
"string".to_string(),
|
||||
Err(_reason) => return Err(ShellError::CantConvert {
|
||||
to_type: "int".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
Some(
|
||||
help: Some(
|
||||
r#"hexadecimal digits following "0x" should be in 0-9, a-f, or A-F"#
|
||||
.to_string(),
|
||||
),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
Ok(num)
|
||||
}
|
||||
@ -347,12 +352,12 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
let num = match i64::from_str_radix(o.trim_start_matches("0o"), 8) {
|
||||
Ok(n) => n,
|
||||
Err(_reason) => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"int".to_string(),
|
||||
"string".to_string(),
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "int".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
Some(r#"octal digits following "0o" should be in 0-7"#.to_string()),
|
||||
))
|
||||
help: Some(r#"octal digits following "0o" should be in 0-7"#.to_string()),
|
||||
})
|
||||
}
|
||||
};
|
||||
Ok(num)
|
||||
@ -361,14 +366,14 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
Ok(n) => Ok(n),
|
||||
Err(_) => match a_string.parse::<f64>() {
|
||||
Ok(f) => Ok(f as i64),
|
||||
_ => Err(ShellError::CantConvert(
|
||||
"int".to_string(),
|
||||
"string".to_string(),
|
||||
_ => Err(ShellError::CantConvert {
|
||||
to_type: "int".to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
Some(format!(
|
||||
help: Some(format!(
|
||||
r#"string "{trimmed}" does not represent a valid integer"#
|
||||
)),
|
||||
)),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -247,28 +247,28 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
span: _,
|
||||
} => Value::Error {
|
||||
// Watch out for CantConvert's argument order
|
||||
error: ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"record".into(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: "record".into(),
|
||||
span,
|
||||
Some("try using the `to nuon` command".into()),
|
||||
),
|
||||
help: Some("try using the `to nuon` command".into()),
|
||||
},
|
||||
},
|
||||
Value::Binary { .. } => Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"binary".into(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "string".into(),
|
||||
from_type: "binary".into(),
|
||||
span,
|
||||
Some("try using the `decode` command".into()),
|
||||
),
|
||||
help: Some("try using the `decode` command".into()),
|
||||
},
|
||||
},
|
||||
x => Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
String::from("string"),
|
||||
x.get_type().to_string(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: String::from("string"),
|
||||
from_type: x.get_type().to_string(),
|
||||
span,
|
||||
None,
|
||||
),
|
||||
help: None,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -62,19 +62,19 @@ impl SQLiteDatabase {
|
||||
path: db.path.clone(),
|
||||
ctrlc: db.ctrlc.clone(),
|
||||
}),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"database".into(),
|
||||
"non-database".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "database".into(),
|
||||
from_type: "non-database".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
x => Err(ShellError::CantConvert(
|
||||
"database".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "database".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ impl CustomValue for SQLiteDatabase {
|
||||
|
||||
fn follow_path_int(&self, _count: usize, span: Span) -> Result<Value, ShellError> {
|
||||
// In theory we could support this, but tables don't have an especially well-defined order
|
||||
Err(ShellError::IncompatiblePathAccess("SQLite databases do not support integer-indexed access. Try specifying a table name instead".into(), span))
|
||||
Err(ShellError::IncompatiblePathAccess { type_name: "SQLite databases do not support integer-indexed access. Try specifying a table name instead".into(), span })
|
||||
}
|
||||
|
||||
fn follow_path_string(&self, _column_name: String, span: Span) -> Result<Value, ShellError> {
|
||||
|
@ -109,12 +109,12 @@ impl Command for WithColumn {
|
||||
let df = NuDataFrame::try_from_value(value)?;
|
||||
command_eager(engine_state, stack, call, df)
|
||||
} else {
|
||||
Err(ShellError::CantConvert(
|
||||
"lazy or eager dataframe".into(),
|
||||
value.get_type().to_string(),
|
||||
value.span()?,
|
||||
None,
|
||||
))
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,14 +270,14 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Math(Math::Divide) => match &right {
|
||||
Value::Int { val, span } => {
|
||||
if *val == 0 {
|
||||
Err(ShellError::DivisionByZero(*span))
|
||||
Err(ShellError::DivisionByZero { span: *span })
|
||||
} else {
|
||||
compute_series_i64(&lhs, *val, <ChunkedArray<Int64Type>>::div, lhs_span)
|
||||
}
|
||||
}
|
||||
Value::Float { val, span } => {
|
||||
if val.is_zero() {
|
||||
Err(ShellError::DivisionByZero(*span))
|
||||
Err(ShellError::DivisionByZero { span: *span })
|
||||
} else {
|
||||
compute_series_decimal(&lhs, *val, <ChunkedArray<Float64Type>>::div, lhs_span)
|
||||
}
|
||||
|
@ -240,12 +240,12 @@ impl NuDataFrame {
|
||||
let df = lazy.collect(span)?;
|
||||
Ok(df)
|
||||
} else {
|
||||
Err(ShellError::CantConvert(
|
||||
"lazy or eager dataframe".into(),
|
||||
value.get_type().to_string(),
|
||||
value.span()?,
|
||||
None,
|
||||
))
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,19 +256,19 @@ impl NuDataFrame {
|
||||
df: df.df.clone(),
|
||||
from_lazy: false,
|
||||
}),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"dataframe".into(),
|
||||
"non-dataframe".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "dataframe".into(),
|
||||
from_type: "non-dataframe".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
x => Err(ShellError::CantConvert(
|
||||
"dataframe".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "dataframe".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ impl NuDataFrame {
|
||||
let column = conversion::create_column(&series, row, row + 1, span)?;
|
||||
|
||||
if column.len() == 0 {
|
||||
Err(ShellError::AccessEmptyContent(span))
|
||||
Err(ShellError::AccessEmptyContent { span })
|
||||
} else {
|
||||
let value = column
|
||||
.into_iter()
|
||||
|
@ -72,23 +72,23 @@ impl NuExpression {
|
||||
match value {
|
||||
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<Self>() {
|
||||
Some(expr) => Ok(NuExpression(expr.0.clone())),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"lazy expression".into(),
|
||||
"non-dataframe".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "lazy expression".into(),
|
||||
from_type: "non-dataframe".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
Value::String { val, .. } => Ok(val.lit().into()),
|
||||
Value::Int { val, .. } => Ok(val.lit().into()),
|
||||
Value::Bool { val, .. } => Ok(val.lit().into()),
|
||||
Value::Float { val, .. } => Ok(val.lit().into()),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"lazy expression".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,12 +160,12 @@ impl ExtractedExpr {
|
||||
.map(Self::extract_exprs)
|
||||
.collect::<Result<Vec<ExtractedExpr>, ShellError>>()
|
||||
.map(ExtractedExpr::List),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"expression".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,12 +132,12 @@ impl NuLazyFrame {
|
||||
let df = NuDataFrame::try_from_value(value)?;
|
||||
Ok(NuLazyFrame::from_dataframe(df))
|
||||
} else {
|
||||
Err(ShellError::CantConvert(
|
||||
"lazy or eager dataframe".into(),
|
||||
value.get_type().to_string(),
|
||||
value.span()?,
|
||||
None,
|
||||
))
|
||||
Err(ShellError::CantConvert {
|
||||
to_type: "lazy or eager dataframe".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span()?,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,19 +154,19 @@ impl NuLazyFrame {
|
||||
from_eager: false,
|
||||
schema: None,
|
||||
}),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"lazy frame".into(),
|
||||
"non-dataframe".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "lazy frame".into(),
|
||||
from_type: "non-dataframe".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
x => Err(ShellError::CantConvert(
|
||||
"lazy frame".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy frame".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,20 +93,20 @@ impl NuLazyGroupBy {
|
||||
schema: group.schema.clone(),
|
||||
from_eager: group.from_eager,
|
||||
}),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"lazy groupby".into(),
|
||||
"custom value".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "lazy groupby".into(),
|
||||
from_type: "custom value".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
x => Err(ShellError::CantConvert(
|
||||
"lazy groupby".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "lazy groupby".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,19 +61,19 @@ impl NuWhen {
|
||||
match value {
|
||||
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<Self>() {
|
||||
Some(expr) => Ok(expr.clone()),
|
||||
None => Err(ShellError::CantConvert(
|
||||
"when expression".into(),
|
||||
"non when expression".into(),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "when expression".into(),
|
||||
from_type: "non when expression".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
x => Err(ShellError::CantConvert(
|
||||
"when expression".into(),
|
||||
x.get_type().to_string(),
|
||||
x.span()?,
|
||||
None,
|
||||
)),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: "when expression".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: x.span()?,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
crates/nu-command/src/env/let_env.rs
vendored
8
crates/nu-command/src/env/let_env.rs
vendored
@ -52,10 +52,10 @@ impl Command for LetEnv {
|
||||
.into_value(call.head);
|
||||
|
||||
if env_var.item == "FILE_PWD" || env_var.item == "PWD" {
|
||||
return Err(ShellError::AutomaticEnvVarSetManually(
|
||||
env_var.item,
|
||||
env_var.span,
|
||||
));
|
||||
return Err(ShellError::AutomaticEnvVarSetManually {
|
||||
envvar_name: env_var.item,
|
||||
span: env_var.span,
|
||||
});
|
||||
} else {
|
||||
stack.add_env_var(env_var.item, rhs);
|
||||
}
|
||||
|
15
crates/nu-command/src/env/load_env.rs
vendored
15
crates/nu-command/src/env/load_env.rs
vendored
@ -43,11 +43,17 @@ impl Command for LoadEnv {
|
||||
Some((cols, vals)) => {
|
||||
for (env_var, rhs) in cols.into_iter().zip(vals) {
|
||||
if env_var == "FILE_PWD" {
|
||||
return Err(ShellError::AutomaticEnvVarSetManually(env_var, call.head));
|
||||
return Err(ShellError::AutomaticEnvVarSetManually {
|
||||
envvar_name: env_var,
|
||||
span: call.head,
|
||||
});
|
||||
}
|
||||
|
||||
if env_var == "PWD" {
|
||||
return Err(ShellError::AutomaticEnvVarSetManually(env_var, call.head));
|
||||
return Err(ShellError::AutomaticEnvVarSetManually {
|
||||
envvar_name: env_var,
|
||||
span: call.head,
|
||||
});
|
||||
} else {
|
||||
stack.add_env_var(env_var, rhs);
|
||||
}
|
||||
@ -58,7 +64,10 @@ impl Command for LoadEnv {
|
||||
PipelineData::Value(Value::Record { cols, vals, .. }, ..) => {
|
||||
for (env_var, rhs) in cols.into_iter().zip(vals) {
|
||||
if env_var == "FILE_PWD" {
|
||||
return Err(ShellError::AutomaticEnvVarSetManually(env_var, call.head));
|
||||
return Err(ShellError::AutomaticEnvVarSetManually {
|
||||
envvar_name: env_var,
|
||||
span: call.head,
|
||||
});
|
||||
}
|
||||
|
||||
if env_var == "PWD" {
|
||||
|
26
crates/nu-command/src/env/with_env.rs
vendored
26
crates/nu-command/src/env/with_env.rs
vendored
@ -100,14 +100,15 @@ fn with_env(
|
||||
}
|
||||
}
|
||||
x => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string list or single row".into(),
|
||||
x.get_type().to_string(),
|
||||
call.positional_nth(1)
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: call
|
||||
.positional_nth(1)
|
||||
.expect("already checked through .req")
|
||||
.span,
|
||||
None,
|
||||
));
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -127,14 +128,15 @@ fn with_env(
|
||||
}
|
||||
}
|
||||
x => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string list or single row".into(),
|
||||
x.get_type().to_string(),
|
||||
call.positional_nth(1)
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: call
|
||||
.positional_nth(1)
|
||||
.expect("already checked through .req")
|
||||
.span,
|
||||
None,
|
||||
));
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -101,12 +101,10 @@ impl Command for Save {
|
||||
|
||||
let res = stream_to_file(stream, file, span, progress);
|
||||
if let Some(h) = handler {
|
||||
h.join().map_err(|err| {
|
||||
ShellError::ExternalCommand(
|
||||
"Fail to receive external commands stderr message".to_string(),
|
||||
format!("{err:?}"),
|
||||
span,
|
||||
)
|
||||
h.join().map_err(|err| ShellError::ExternalCommand {
|
||||
label: "Fail to receive external commands stderr message".to_string(),
|
||||
help: format!("{err:?}"),
|
||||
span,
|
||||
})??;
|
||||
res
|
||||
} else {
|
||||
|
@ -110,7 +110,7 @@ fn first_helper(
|
||||
Value::List { vals, .. } => {
|
||||
if return_single_element {
|
||||
if vals.is_empty() {
|
||||
Err(ShellError::AccessEmptyContent(head))
|
||||
Err(ShellError::AccessEmptyContent { span: head })
|
||||
} else {
|
||||
Ok(vals[0].clone().into_pipeline_data())
|
||||
}
|
||||
@ -154,7 +154,7 @@ fn first_helper(
|
||||
if let Some(v) = ls.next() {
|
||||
Ok(v.into_pipeline_data())
|
||||
} else {
|
||||
Err(ShellError::AccessEmptyContent(head))
|
||||
Err(ShellError::AccessEmptyContent { span: head })
|
||||
}
|
||||
} else {
|
||||
Ok(ls
|
||||
|
@ -248,11 +248,11 @@ pub fn group(
|
||||
};
|
||||
match row.get_data_by_key(&column_name.item) {
|
||||
Some(group_key) => Ok(group_key.as_string()?),
|
||||
None => Err(ShellError::CantFindColumn(
|
||||
column_name.item.to_string(),
|
||||
column_name.span,
|
||||
row.expect_span(),
|
||||
)),
|
||||
None => Err(ShellError::CantFindColumn {
|
||||
col_name: column_name.item.to_string(),
|
||||
span: column_name.span,
|
||||
src_span: row.expect_span(),
|
||||
}),
|
||||
}
|
||||
});
|
||||
|
||||
@ -263,9 +263,9 @@ pub fn group(
|
||||
|
||||
data_group(values, &Some(block), name)
|
||||
}
|
||||
Grouper::ByBlock => Err(ShellError::NushellFailed(
|
||||
"Block not implemented: This should never happen.".into(),
|
||||
)),
|
||||
Grouper::ByBlock => Err(ShellError::NushellFailed {
|
||||
msg: "Block not implemented: This should never happen.".into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,11 +262,11 @@ fn move_record_columns(
|
||||
out_cols.push(col.into());
|
||||
out_vals.push(val.clone());
|
||||
} else {
|
||||
return Err(ShellError::NushellFailedSpanned(
|
||||
"Error indexing input columns".to_string(),
|
||||
"originates from here".to_string(),
|
||||
return Err(ShellError::NushellFailedSpanned {
|
||||
msg: "Error indexing input columns".to_string(),
|
||||
label: "originates from here".to_string(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,11 +276,11 @@ fn move_record_columns(
|
||||
out_cols.push(col.into());
|
||||
out_vals.push(val.clone());
|
||||
} else {
|
||||
return Err(ShellError::NushellFailedSpanned(
|
||||
"Error indexing input columns".to_string(),
|
||||
"originates from here".to_string(),
|
||||
return Err(ShellError::NushellFailedSpanned {
|
||||
msg: "Error indexing input columns".to_string(),
|
||||
label: "originates from here".to_string(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,11 +164,11 @@ pub fn split(
|
||||
Box::new(
|
||||
move |_, row: &Value| match row.get_data_by_key(&column_name.item) {
|
||||
Some(group_key) => Ok(group_key.as_string()?),
|
||||
None => Err(ShellError::CantFindColumn(
|
||||
column_name.item.to_string(),
|
||||
column_name.span,
|
||||
row.span().unwrap_or(column_name.span),
|
||||
)),
|
||||
None => Err(ShellError::CantFindColumn {
|
||||
col_name: column_name.item.to_string(),
|
||||
span: column_name.span,
|
||||
src_span: row.span().unwrap_or(column_name.span),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -135,7 +135,11 @@ fn validate(vec: Vec<Value>, columns: &Vec<String>, span: Span) -> Result<(), Sh
|
||||
}
|
||||
|
||||
if let Some(nonexistent) = nonexistent_column(columns.clone(), cols.to_vec()) {
|
||||
return Err(ShellError::CantFindColumn(nonexistent, span, *val_span));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: nonexistent,
|
||||
span,
|
||||
src_span: *val_span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,12 @@ fn update(
|
||||
if let Some(v) = input.next() {
|
||||
pre_elems.push(v);
|
||||
} else if idx == 0 {
|
||||
return Err(ShellError::AccessEmptyContent(*span));
|
||||
return Err(ShellError::AccessEmptyContent { span: *span });
|
||||
} else {
|
||||
return Err(ShellError::AccessBeyondEnd(idx - 1, *span));
|
||||
return Err(ShellError::AccessBeyondEnd {
|
||||
max_idx: idx - 1,
|
||||
span: *span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,10 @@ fn upsert(
|
||||
if let Some(v) = input.next() {
|
||||
pre_elems.push(v);
|
||||
} else {
|
||||
return Err(ShellError::AccessBeyondEnd(idx, *span));
|
||||
return Err(ShellError::AccessBeyondEnd {
|
||||
max_idx: idx,
|
||||
span: *span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,12 +119,12 @@ fn convert_nujson_to_value(value: &nu_json::Value, span: Span) -> Value {
|
||||
nu_json::Value::U64(u) => {
|
||||
if *u > i64::MAX as u64 {
|
||||
Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"i64 sized integer".into(),
|
||||
"value larger than i64".into(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "i64 sized integer".into(),
|
||||
from_type: "value larger than i64".into(),
|
||||
span,
|
||||
None,
|
||||
),
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Value::Int {
|
||||
@ -182,12 +182,12 @@ fn convert_string_to_value(string_input: String, span: Span) -> Result<Value, Sh
|
||||
)],
|
||||
))
|
||||
}
|
||||
x => Err(ShellError::CantConvert(
|
||||
format!("structured json data ({x})"),
|
||||
"string".into(),
|
||||
x => Err(ShellError::CantConvert {
|
||||
to_type: format!("structured json data ({x})"),
|
||||
from_type: "string".into(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
help: None,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -106,12 +106,12 @@ pub fn convert_string_to_value(string_input: String, span: Span) -> Result<Value
|
||||
match result {
|
||||
Ok(value) => Ok(convert_toml_to_value(&value, span)),
|
||||
|
||||
Err(err) => Err(ShellError::CantConvert(
|
||||
"structured toml data".into(),
|
||||
"string".into(),
|
||||
Err(err) => Err(ShellError::CantConvert {
|
||||
to_type: "structured toml data".into(),
|
||||
from_type: "string".into(),
|
||||
span,
|
||||
Some(err.to_string()),
|
||||
)),
|
||||
help: Some(err.to_string()),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,12 @@ fn writer_to_string(writer: Writer<Vec<u8>>) -> Result<String, Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn make_conversion_error(type_from: &str, span: &Span) -> ShellError {
|
||||
ShellError::CantConvert(type_from.to_string(), "string".to_string(), *span, None)
|
||||
ShellError::CantConvert {
|
||||
to_type: type_from.to_string(),
|
||||
from_type: "string".to_string(),
|
||||
span: *span,
|
||||
help: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_string_tagged_value(
|
||||
@ -174,12 +179,12 @@ pub fn to_delimited_data(
|
||||
}
|
||||
Ok(x)
|
||||
}
|
||||
Err(_) => Err(ShellError::CantConvert(
|
||||
format_name.into(),
|
||||
value.get_type().to_string(),
|
||||
value.span().unwrap_or(span),
|
||||
None,
|
||||
)),
|
||||
Err(_) => Err(ShellError::CantConvert {
|
||||
to_type: format_name.into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: value.span().unwrap_or(span),
|
||||
help: None,
|
||||
}),
|
||||
}?;
|
||||
Ok(Value::string(output, span).into_pipeline_data())
|
||||
}
|
||||
|
@ -70,12 +70,12 @@ impl Command for ToJson {
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
_ => Ok(Value::Error {
|
||||
error: ShellError::CantConvert(
|
||||
"JSON".into(),
|
||||
value.get_type().to_string(),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "JSON".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span,
|
||||
None,
|
||||
),
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
|
@ -118,7 +118,12 @@ fn toml_into_pipeline_data(
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
_ => Ok(Value::Error {
|
||||
error: ShellError::CantConvert("TOML".into(), value_type.to_string(), span, None),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "TOML".into(),
|
||||
from_type: value_type.to_string(),
|
||||
span,
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
|
@ -185,12 +185,12 @@ fn to_xml(
|
||||
};
|
||||
Ok(Value::string(s, head).into_pipeline_data())
|
||||
}
|
||||
Err(_) => Err(ShellError::CantConvert(
|
||||
"XML".into(),
|
||||
value_type.to_string(),
|
||||
head,
|
||||
None,
|
||||
)),
|
||||
Err(_) => Err(ShellError::CantConvert {
|
||||
to_type: "XML".into(),
|
||||
from_type: value_type.to_string(),
|
||||
span: head,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,12 @@ fn to_yaml(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
_ => Ok(Value::Error {
|
||||
error: ShellError::CantConvert("YAML".into(), value.get_type().to_string(), head, None),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: "YAML".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: head,
|
||||
help: None,
|
||||
},
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
}
|
||||
|
@ -241,12 +241,12 @@ pub fn request_add_custom_headers(
|
||||
}
|
||||
|
||||
x => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string list or single row".into(),
|
||||
x.get_type().to_string(),
|
||||
headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
None,
|
||||
));
|
||||
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)),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -260,12 +260,12 @@ pub fn request_add_custom_headers(
|
||||
}
|
||||
|
||||
x => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"string list or single row".into(),
|
||||
x.get_type().to_string(),
|
||||
headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
None,
|
||||
));
|
||||
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)),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -89,12 +89,12 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
|
||||
|
||||
match serde_urlencoded::to_string(row_vec) {
|
||||
Ok(s) => Ok(s),
|
||||
_ => Err(ShellError::CantConvert(
|
||||
"URL".into(),
|
||||
value.get_type().to_string(),
|
||||
head,
|
||||
None,
|
||||
)),
|
||||
_ => Err(ShellError::CantConvert {
|
||||
to_type: "URL".into(),
|
||||
from_type: value.get_type().to_string(),
|
||||
span: head,
|
||||
help: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
// Propagate existing errors
|
||||
|
@ -128,7 +128,12 @@ fn relative_to(path: &Path, span: Span, args: &Arguments) -> Value {
|
||||
match lhs.strip_prefix(&rhs) {
|
||||
Ok(p) => Value::string(p.to_string_lossy(), span),
|
||||
Err(e) => Value::Error {
|
||||
error: ShellError::CantConvert(e.to_string(), "string".into(), span, None),
|
||||
error: ShellError::CantConvert {
|
||||
to_type: e.to_string(),
|
||||
from_type: "string".into(),
|
||||
span,
|
||||
help: None,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ fn bool(
|
||||
let probability_is_valid = (0.0..=1.0).contains(&probability);
|
||||
|
||||
if !probability_is_valid {
|
||||
return Err(ShellError::InvalidProbability(prob.span));
|
||||
return Err(ShellError::InvalidProbability { span: prob.span });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,9 @@ impl Command for GotoShell {
|
||||
let n = shell_span
|
||||
.item
|
||||
.parse::<usize>()
|
||||
.map_err(|_| ShellError::NotFound(shell_span.span))?;
|
||||
.map_err(|_| ShellError::NotFound {
|
||||
span: shell_span.span,
|
||||
})?;
|
||||
|
||||
switch_shell(engine_state, stack, call, shell_span.span, SwitchTo::Nth(n))
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ fn switch_shell(
|
||||
|
||||
let new_path = shells
|
||||
.get(new_shell)
|
||||
.ok_or(ShellError::NotFound(span))?
|
||||
.ok_or(ShellError::NotFound { span })?
|
||||
.to_owned();
|
||||
|
||||
stack.add_env_var(
|
||||
|
@ -89,7 +89,11 @@ pub fn sort(
|
||||
}
|
||||
|
||||
if let Some(nonexistent) = nonexistent_column(sort_columns.clone(), cols.to_vec()) {
|
||||
return Err(ShellError::CantFindColumn(nonexistent, span, *val_span));
|
||||
return Err(ShellError::CantFindColumn {
|
||||
col_name: nonexistent,
|
||||
span,
|
||||
src_span: *val_span,
|
||||
});
|
||||
}
|
||||
|
||||
// check to make sure each value in each column in the record
|
||||
|
@ -95,12 +95,10 @@ impl Command for Complete {
|
||||
|
||||
if let Some((handler, stderr_span)) = stderr_handler {
|
||||
cols.push("stderr".to_string());
|
||||
let res = handler.join().map_err(|err| {
|
||||
ShellError::ExternalCommand(
|
||||
"Fail to receive external commands stderr message".to_string(),
|
||||
format!("{err:?}"),
|
||||
stderr_span,
|
||||
)
|
||||
let res = handler.join().map_err(|err| ShellError::ExternalCommand {
|
||||
label: "Fail to receive external commands stderr message".to_string(),
|
||||
help: format!("{err:?}"),
|
||||
span: stderr_span,
|
||||
})??;
|
||||
vals.push(res)
|
||||
};
|
||||
|
@ -291,7 +291,7 @@ fn heuristic_parse_file(
|
||||
Err(ShellError::IOError("Can not read input".to_string()))
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::NotFound(call.head))
|
||||
Err(ShellError::NotFound { span: call.head })
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ fn parse_file_script(
|
||||
Err(ShellError::IOError("Can not read path".to_string()))
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::NotFound(call.head))
|
||||
Err(ShellError::NotFound { span: call.head })
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,6 +396,6 @@ fn parse_file_module(
|
||||
Err(ShellError::IOError("Can not read path".to_string()))
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::NotFound(call.head))
|
||||
Err(ShellError::NotFound { span: call.head })
|
||||
}
|
||||
}
|
||||
|
@ -106,12 +106,10 @@ pub fn create_external_command(
|
||||
value
|
||||
.as_string()
|
||||
.map(|item| Spanned { item, span })
|
||||
.map_err(|_| {
|
||||
ShellError::ExternalCommand(
|
||||
format!("Cannot convert {} to a string", value.get_type()),
|
||||
"All arguments to an external command need to be string-compatible".into(),
|
||||
span,
|
||||
)
|
||||
.map_err(|_| ShellError::ExternalCommand {
|
||||
label: format!("Cannot convert {} to a string", value.get_type()),
|
||||
help: "All arguments to an external command need to be string-compatible".into(),
|
||||
span,
|
||||
})
|
||||
}
|
||||
|
||||
@ -326,18 +324,18 @@ impl ExternalCommand {
|
||||
}
|
||||
};
|
||||
|
||||
Err(ShellError::ExternalCommand(
|
||||
Err(ShellError::ExternalCommand {
|
||||
label,
|
||||
err.to_string(),
|
||||
self.name.span,
|
||||
))
|
||||
help: err.to_string(),
|
||||
span: self.name.span,
|
||||
})
|
||||
}
|
||||
// otherwise, a default error message
|
||||
_ => Err(ShellError::ExternalCommand(
|
||||
"can't run executable".into(),
|
||||
err.to_string(),
|
||||
self.name.span,
|
||||
)),
|
||||
_ => Err(ShellError::ExternalCommand {
|
||||
label: "can't run executable".into(),
|
||||
help: err.to_string(),
|
||||
span: self.name.span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
Ok(mut child) => {
|
||||
@ -408,23 +406,15 @@ impl ExternalCommand {
|
||||
.spawn(move || {
|
||||
if redirect_stdout {
|
||||
let stdout = stdout.ok_or_else(|| {
|
||||
ShellError::ExternalCommand(
|
||||
"Error taking stdout from external".to_string(),
|
||||
"Redirects need access to stdout of an external command"
|
||||
.to_string(),
|
||||
span,
|
||||
)
|
||||
ShellError::ExternalCommand { label: "Error taking stdout from external".to_string(), help: "Redirects need access to stdout of an external command"
|
||||
.to_string(), span }
|
||||
})?;
|
||||
|
||||
read_and_redirect_message(stdout, stdout_tx, ctrlc)
|
||||
}
|
||||
|
||||
match child.as_mut().wait() {
|
||||
Err(err) => Err(ShellError::ExternalCommand(
|
||||
"External command exited with error".into(),
|
||||
err.to_string(),
|
||||
span,
|
||||
)),
|
||||
Err(err) => Err(ShellError::ExternalCommand { label: "External command exited with error".into(), help: err.to_string(), span }),
|
||||
Ok(x) => {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
@ -455,11 +445,7 @@ impl ExternalCommand {
|
||||
))
|
||||
);
|
||||
let _ = exit_code_tx.send(Value::Error {
|
||||
error: ShellError::ExternalCommand(
|
||||
"core dumped".to_string(),
|
||||
format!("{cause}: child process '{commandname}' core dumped"),
|
||||
head,
|
||||
),
|
||||
error: ShellError::ExternalCommand { label: "core dumped".to_string(), help: format!("{cause}: child process '{commandname}' core dumped"), span: head },
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
@ -481,13 +467,11 @@ impl ExternalCommand {
|
||||
thread::Builder::new()
|
||||
.name("stderr redirector".to_string())
|
||||
.spawn(move || {
|
||||
let stderr = stderr.ok_or_else(|| {
|
||||
ShellError::ExternalCommand(
|
||||
"Error taking stderr from external".to_string(),
|
||||
"Redirects need access to stderr of an external command"
|
||||
.to_string(),
|
||||
span,
|
||||
)
|
||||
let stderr = stderr.ok_or_else(|| ShellError::ExternalCommand {
|
||||
label: "Error taking stderr from external".to_string(),
|
||||
help: "Redirects need access to stderr of an external command"
|
||||
.to_string(),
|
||||
span,
|
||||
})?;
|
||||
|
||||
read_and_redirect_message(stderr, stderr_tx, stderr_ctrlc);
|
||||
|
Reference in New Issue
Block a user