Merge pull request #250 from jonathandturner/more_error_fixes

More touchups to errors
This commit is contained in:
Jonathan Turner 2019-08-06 15:19:45 +12:00 committed by GitHub
commit bb50f1eb14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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", "Expected a string from pipeline",
"requires string input", "requires string input",
span, span,
"value originates from here", format!("{} originates from here", x.type_name()),
a.span(), value_tag.span,
)), )),
} }
}) })

View File

@ -20,7 +20,7 @@ command! {
let full_path = PathBuf::from(cwd); 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())?; 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(); let mut result = VecDeque::new();
for s in split_result { for s in split_result {
result.push_back(ReturnSuccess::value( 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 result

View File

@ -45,10 +45,12 @@ pub fn to_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(x) => ReturnSuccess::value( Ok(x) => ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span), Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
), ),
Err(_) => Err(ShellError::labeled_error( _ => Err(ShellError::labeled_error_with_secondary(
"Can not convert to CSV string", "Expected an object with CSV-compatible structure from pipeline",
"can not convert piped data to CSV string", "requires CSV-compatible input",
name_span, name_span,
format!("{} originates from here", a.item.type_name()),
a.span(),
)), )),
}) })
.to_output_stream()) .to_output_stream())

View File

@ -51,10 +51,12 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(x) => ReturnSuccess::value( Ok(x) => ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span), Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
), ),
Err(_) => Err(ShellError::labeled_error( _ => Err(ShellError::labeled_error_with_secondary(
"Can not convert to JSON string", "Expected an object with JSON-compatible structure from pipeline",
"can not convert piped data to JSON string", "requires JSON-compatible input",
name_span, 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), Value::Primitive(Primitive::String(val)).simple_spanned(name_span),
) )
} }
_ => Err(ShellError::labeled_error_with_secondary(
Err(err) => Err(ShellError::type_error( "Expected an object with TOML-compatible structure from pipeline",
"Can not convert to a TOML string", "requires TOML-compatible input",
format!("{:?} - {:?}", a.type_name(), err).simple_spanned(name_span), name_span,
format!("{} originates from here", a.item.type_name()),
a.span(),
)), )),
}) })
.to_output_stream()) .to_output_stream())

View File

@ -49,10 +49,12 @@ pub fn to_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(x) => ReturnSuccess::value( Ok(x) => ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span), Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
), ),
Err(_) => Err(ShellError::labeled_error( _ => Err(ShellError::labeled_error_with_secondary(
"Can not convert to YAML string", "Expected an object with YAML-compatible structure from pipeline",
"can not convert piped data to YAML string", "requires YAML-compatible input",
name_span, 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> { impl<T: ExtractType> ExtractType for Tagged<T> {
fn extract(value: &Tagged<Value>) -> Result<Tagged<T>, ShellError> { 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> { fn check(value: &'value Tagged<Value>) -> Result<&'value Tagged<Value>, ShellError> {