mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
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:
@ -127,13 +127,12 @@ fn action(
|
||||
Value::string(std::str::from_utf8(&enc_vec).unwrap_or(""), command_span)
|
||||
}
|
||||
ActionType::Decode => Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"Binary data can only be encoded".to_string(),
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.span(),
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "Binary data can only be encoded".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: command_span,
|
||||
input_span: input.span(),
|
||||
},
|
||||
command_span,
|
||||
),
|
||||
},
|
||||
|
@ -99,12 +99,12 @@ documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics"#
|
||||
}
|
||||
// This should be more precise, but due to difficulties in getting spans
|
||||
// from PipelineData::ListData, this is as it is.
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"non-binary input".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
input.span().unwrap_or(head),
|
||||
)),
|
||||
_ => Err(ShellError::UnsupportedInput {
|
||||
msg: "non-binary input".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: input.span().unwrap_or(head),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,12 +113,12 @@ documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics"#
|
||||
}
|
||||
// This should be more precise, but due to difficulties in getting spans
|
||||
// from PipelineData::ListStream, this is as it is.
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"non-string input".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
input.span().unwrap_or(head),
|
||||
)),
|
||||
_ => Err(ShellError::UnsupportedInput {
|
||||
msg: "non-string input".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: input.span().unwrap_or(head),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ pub fn detect_encoding_name(
|
||||
//Guess(TLD=None(usually used in HTML), Allow_UTF8=True)
|
||||
let (encoding, is_certain) = detector.guess_assess(None, true);
|
||||
if !is_certain {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Input contains unknown encoding, try giving a encoding name".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
input,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Input contains unknown encoding, try giving a encoding name".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: input,
|
||||
});
|
||||
}
|
||||
Ok(encoding)
|
||||
}
|
||||
|
@ -191,13 +191,12 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"Only string values are supported".into(),
|
||||
format!("input type: {:?}", other.get_type()),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.span(),
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "Only string values are supported".into(),
|
||||
input: format!("input type: {:?}", other.get_type()),
|
||||
msg_span: head,
|
||||
input_span: other.span(),
|
||||
},
|
||||
head,
|
||||
),
|
||||
}
|
||||
|
@ -198,18 +198,15 @@ fn action(input: &Value, arg: &Arguments, head: Span) -> Value {
|
||||
}
|
||||
_ => input.clone(),
|
||||
},
|
||||
ActionMode::Local => {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"Only string values are supported".into(),
|
||||
format!("input type: {:?}", other.get_type()),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.span(),
|
||||
),
|
||||
head,
|
||||
)
|
||||
}
|
||||
ActionMode::Local => Value::error(
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "Only string values are supported".into(),
|
||||
input: format!("input type: {:?}", other.get_type()),
|
||||
msg_span: head,
|
||||
input_span: other.span(),
|
||||
},
|
||||
head,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user