mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
More touchups to errors
This commit is contained in:
parent
d8c4f73ca4
commit
ae5b781159
8 changed files with 27 additions and 19 deletions
|
@ -59,12 +59,12 @@ pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
)),
|
||||
}
|
||||
}
|
||||
_ => Err(ShellError::labeled_error_with_secondary(
|
||||
x => Err(ShellError::labeled_error_with_secondary(
|
||||
"Expected a string from pipeline",
|
||||
"requires string input",
|
||||
span,
|
||||
"value originates from here",
|
||||
a.span(),
|
||||
format!("{} originates from here", x.type_name()),
|
||||
value_tag.span,
|
||||
)),
|
||||
}
|
||||
})
|
||||
|
|
|
@ -20,7 +20,7 @@ command! {
|
|||
|
||||
let full_path = PathBuf::from(cwd);
|
||||
|
||||
let path_str = path.to_str().ok_or(ShellError::type_error("Path", "invalid path".simple_spanned(path.span())))?;
|
||||
let path_str = path.to_str().ok_or(ShellError::type_error("Path", "invalid path".tagged(path.tag())))?;
|
||||
|
||||
let (file_extension, contents, contents_tag, span_source) = fetch(&full_path, path_str, path.span())?;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn split_row(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
let mut result = VecDeque::new();
|
||||
for s in split_result {
|
||||
result.push_back(ReturnSuccess::value(
|
||||
Value::Primitive(Primitive::String(s.into())).simple_spanned(v.span()),
|
||||
Value::Primitive(Primitive::String(s.into())).tagged(v.tag()),
|
||||
));
|
||||
}
|
||||
result
|
||||
|
|
|
@ -45,10 +45,12 @@ pub fn to_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
Ok(x) => ReturnSuccess::value(
|
||||
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
|
||||
),
|
||||
Err(_) => Err(ShellError::labeled_error(
|
||||
"Can not convert to CSV string",
|
||||
"can not convert piped data to CSV string",
|
||||
_ => Err(ShellError::labeled_error_with_secondary(
|
||||
"Expected an object with CSV-compatible structure from pipeline",
|
||||
"requires CSV-compatible input",
|
||||
name_span,
|
||||
format!("{} originates from here", a.item.type_name()),
|
||||
a.span(),
|
||||
)),
|
||||
})
|
||||
.to_output_stream())
|
||||
|
|
|
@ -51,10 +51,12 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
Ok(x) => ReturnSuccess::value(
|
||||
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
|
||||
),
|
||||
Err(_) => Err(ShellError::labeled_error(
|
||||
"Can not convert to JSON string",
|
||||
"can not convert piped data to JSON string",
|
||||
_ => Err(ShellError::labeled_error_with_secondary(
|
||||
"Expected an object with JSON-compatible structure from pipeline",
|
||||
"requires JSON-compatible input",
|
||||
name_span,
|
||||
format!("{} originates from here", a.item.type_name()),
|
||||
a.span(),
|
||||
)),
|
||||
},
|
||||
)
|
||||
|
|
|
@ -45,10 +45,12 @@ pub fn to_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
Value::Primitive(Primitive::String(val)).simple_spanned(name_span),
|
||||
)
|
||||
}
|
||||
|
||||
Err(err) => Err(ShellError::type_error(
|
||||
"Can not convert to a TOML string",
|
||||
format!("{:?} - {:?}", a.type_name(), err).simple_spanned(name_span),
|
||||
_ => Err(ShellError::labeled_error_with_secondary(
|
||||
"Expected an object with TOML-compatible structure from pipeline",
|
||||
"requires TOML-compatible input",
|
||||
name_span,
|
||||
format!("{} originates from here", a.item.type_name()),
|
||||
a.span(),
|
||||
)),
|
||||
})
|
||||
.to_output_stream())
|
||||
|
|
|
@ -49,10 +49,12 @@ pub fn to_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
Ok(x) => ReturnSuccess::value(
|
||||
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
|
||||
),
|
||||
Err(_) => Err(ShellError::labeled_error(
|
||||
"Can not convert to YAML string",
|
||||
"can not convert piped data to YAML string",
|
||||
_ => Err(ShellError::labeled_error_with_secondary(
|
||||
"Expected an object with YAML-compatible structure from pipeline",
|
||||
"requires YAML-compatible input",
|
||||
name_span,
|
||||
format!("{} originates from here", a.item.type_name()),
|
||||
a.span(),
|
||||
)),
|
||||
},
|
||||
)
|
||||
|
|
|
@ -21,7 +21,7 @@ pub trait ExtractType: Sized {
|
|||
|
||||
impl<T: ExtractType> ExtractType for Tagged<T> {
|
||||
fn extract(value: &Tagged<Value>) -> Result<Tagged<T>, ShellError> {
|
||||
Ok(T::extract(value)?.simple_spanned(value.span()))
|
||||
Ok(T::extract(value)?.tagged(value.tag()))
|
||||
}
|
||||
|
||||
fn check(value: &'value Tagged<Value>) -> Result<&'value Tagged<Value>, ShellError> {
|
||||
|
|
Loading…
Reference in a new issue