Improve error messages for save

`save` attempts to convert input based on the target filename extension,
and expects a stream of text otherwise. However the error message is
unclear and provides little guidance, hopefully this is less confusing
to new users.

It might be worthwhile to also add a hint about adding an extension,
though I'm not sure if it's possible to emit multiple diagnostics.
This commit is contained in:
Belhorma Bendebiche 2019-11-16 19:04:33 -05:00
parent 57d425d929
commit 946f7256e4

View File

@ -19,8 +19,8 @@ macro_rules! process_string {
}
_ => {
break $scope Err(ShellError::labeled_error(
"Save could not successfully save",
"unexpected data during save",
"Save requires formatted data",
"consider piping to a converter (see `help commands`)",
$name_tag,
));
}
@ -214,9 +214,9 @@ fn save(
match content {
Ok(save_data) => match std::fs::write(full_path, save_data) {
Ok(o) => o,
Err(e) => yield Err(ShellError::labeled_error(e.to_string(), "for command", name)),
Err(e) => yield Err(ShellError::labeled_error(e.to_string(), "IO error while saving", name)),
},
Err(e) => yield Err(ShellError::labeled_error(e.to_string(), "for command", name)),
Err(e) => yield Err(e),
}
};