forked from extern/nushell
Convert ShellError::UnsupportedInput to named fields (#10971)
# Description This is easy to do with rust-analyzer, but I didn't want to just pump these all out without feedback. Part of #10700 # User-Facing Changes None # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
@ -126,12 +126,12 @@ fn to_string_tagged_value(
|
||||
}
|
||||
|
||||
fn make_unsupported_input_error(value: &Value, head: Span, span: Span) -> ShellError {
|
||||
ShellError::UnsupportedInput(
|
||||
"Unexpected type".to_string(),
|
||||
format!("input type: {:?}", value.get_type()),
|
||||
head,
|
||||
span,
|
||||
)
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "Unexpected type".to_string(),
|
||||
input: format!("input type: {:?}", value.get_type()),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_non_record(values: &[Value]) -> Option<&Value> {
|
||||
|
@ -131,28 +131,28 @@ pub fn value_to_string(
|
||||
let mut s = String::with_capacity(2 * val.len());
|
||||
for byte in val {
|
||||
if write!(s, "{byte:02X}").is_err() {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"could not convert binary to string".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "could not convert binary to string".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_span: v.span(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(format!("0x[{s}]"))
|
||||
}
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput(
|
||||
"blocks are currently not nuon-compatible".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
)),
|
||||
Value::Closure { .. } => Err(ShellError::UnsupportedInput(
|
||||
"closures are currently not nuon-compatible".into(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
)),
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput {
|
||||
msg: "blocks are currently not nuon-compatible".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_span: v.span(),
|
||||
}),
|
||||
Value::Closure { .. } => Err(ShellError::UnsupportedInput {
|
||||
msg: "closures are currently not nuon-compatible".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_span: v.span(),
|
||||
}),
|
||||
Value::Bool { val, .. } => {
|
||||
if *val {
|
||||
Ok("true".to_string())
|
||||
@ -160,18 +160,18 @@ pub fn value_to_string(
|
||||
Ok("false".to_string())
|
||||
}
|
||||
}
|
||||
Value::CellPath { .. } => Err(ShellError::UnsupportedInput(
|
||||
"cell-paths are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
)),
|
||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput(
|
||||
"custom values are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
)),
|
||||
Value::CellPath { .. } => Err(ShellError::UnsupportedInput {
|
||||
msg: "cell-paths are currently not nuon-compatible".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_span: v.span(),
|
||||
}),
|
||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput {
|
||||
msg: "custom values are currently not nuon-compatible".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_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)),
|
||||
@ -241,12 +241,12 @@ pub fn value_to_string(
|
||||
))
|
||||
}
|
||||
}
|
||||
Value::MatchPattern { .. } => Err(ShellError::UnsupportedInput(
|
||||
"match patterns are currently not nuon-compatible".to_string(),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
v.span(),
|
||||
)),
|
||||
Value::MatchPattern { .. } => Err(ShellError::UnsupportedInput {
|
||||
msg: "match patterns are currently not nuon-compatible".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: span,
|
||||
input_span: v.span(),
|
||||
}),
|
||||
Value::Nothing { .. } => Ok("null".to_string()),
|
||||
Value::Range { val, .. } => Ok(format!(
|
||||
"{}..{}{}",
|
||||
|
@ -137,12 +137,12 @@ fn value_to_toml_value(
|
||||
Value::Record { .. } => helper(engine_state, v),
|
||||
// Propagate existing errors
|
||||
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.span(),
|
||||
)),
|
||||
_ => Err(ShellError::UnsupportedInput {
|
||||
msg: format!("{:?} is not valid top-level TOML", v.get_type()),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: v.span(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user