More touchups to errors

This commit is contained in:
Jonathan Turner 2019-08-06 15:03:13 +12:00
parent d8c4f73ca4
commit ae5b781159
8 changed files with 27 additions and 19 deletions

View file

@ -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,
)),
}
})

View file

@ -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())?;

View file

@ -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

View file

@ -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())

View file

@ -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(),
)),
},
)

View file

@ -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())

View file

@ -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(),
)),
},
)

View file

@ -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> {