mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Add ErrSpan
extension trait for Result
(#12626)
# Description This adds an extension trait to `Result` that wraps errors in `Spanned`, saving the effort of calling `.map_err(|err| err.into_spanned(span))` every time. This will hopefully make it even more likely that someone will want to use a spanned `io::Error` and make it easier to remove the impl for `From<io::Error> for ShellError` because that doesn't have span information.
This commit is contained in:
@ -106,9 +106,7 @@ apparent the next time `nu` is next launched with that plugin cache file.
|
||||
|
||||
let shell_expanded = shell
|
||||
.as_ref()
|
||||
.map(|s| {
|
||||
nu_path::canonicalize_with(&s.item, &cwd).map_err(|err| err.into_spanned(s.span))
|
||||
})
|
||||
.map(|s| nu_path::canonicalize_with(&s.item, &cwd).err_span(s.span))
|
||||
.transpose()?;
|
||||
|
||||
// Parse the plugin filename so it can be used to spawn the plugin
|
||||
|
@ -30,7 +30,7 @@ pub(crate) fn modify_plugin_file(
|
||||
// Try to read the plugin file if it exists
|
||||
let mut contents = if fs::metadata(&plugin_cache_file_path).is_ok_and(|m| m.len() > 0) {
|
||||
PluginCacheFile::read_from(
|
||||
File::open(&plugin_cache_file_path).map_err(|err| err.into_spanned(span))?,
|
||||
File::open(&plugin_cache_file_path).err_span(span)?,
|
||||
Some(span),
|
||||
)?
|
||||
} else {
|
||||
@ -42,7 +42,7 @@ pub(crate) fn modify_plugin_file(
|
||||
|
||||
// Save the modified file on success
|
||||
contents.write_to(
|
||||
File::create(&plugin_cache_file_path).map_err(|err| err.into_spanned(span))?,
|
||||
File::create(&plugin_cache_file_path).err_span(span)?,
|
||||
Some(span),
|
||||
)?;
|
||||
|
||||
|
Reference in New Issue
Block a user