mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:15:49 +02:00
Refactor: Construct IoError
from std::io::Error
instead of std::io::ErrorKind
(#15777)
This commit is contained in:
@ -88,13 +88,19 @@ apparent the next time `nu` is next launched with that plugin registry file.
|
||||
let filename_expanded = nu_path::locate_in_dirs(&filename.item, &cwd, || {
|
||||
get_plugin_dirs(engine_state, stack)
|
||||
})
|
||||
.map_err(|err| IoError::new(err.kind(), filename.span, PathBuf::from(filename.item)))?;
|
||||
.map_err(|err| {
|
||||
IoError::new(
|
||||
err.not_found_as(NotFound::File),
|
||||
filename.span,
|
||||
PathBuf::from(filename.item),
|
||||
)
|
||||
})?;
|
||||
|
||||
let shell_expanded = shell
|
||||
.as_ref()
|
||||
.map(|s| {
|
||||
nu_path::canonicalize_with(&s.item, &cwd)
|
||||
.map_err(|err| IoError::new(err.kind(), s.span, None))
|
||||
.map_err(|err| IoError::new(err, s.span, None))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
#[allow(deprecated)]
|
||||
use nu_engine::{command_prelude::*, current_dir};
|
||||
use nu_protocol::{PluginRegistryFile, engine::StateWorkingSet, shell_error::io::IoError};
|
||||
use nu_protocol::{
|
||||
PluginRegistryFile,
|
||||
engine::StateWorkingSet,
|
||||
shell_error::{self, io::IoError},
|
||||
};
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
path::PathBuf,
|
||||
@ -46,12 +50,12 @@ pub(crate) fn read_plugin_file(
|
||||
if fs::metadata(&plugin_registry_file_path).is_ok_and(|m| m.len() > 0) {
|
||||
PluginRegistryFile::read_from(
|
||||
File::open(&plugin_registry_file_path)
|
||||
.map_err(|err| IoError::new(err.kind(), file_span, plugin_registry_file_path))?,
|
||||
.map_err(|err| IoError::new(err, file_span, plugin_registry_file_path))?,
|
||||
Some(file_span),
|
||||
)
|
||||
} else if let Some(path) = custom_path {
|
||||
Err(ShellError::Io(IoError::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
shell_error::io::ErrorKind::FileNotFound,
|
||||
path.span,
|
||||
PathBuf::from(&path.item),
|
||||
)))
|
||||
@ -75,9 +79,8 @@ pub(crate) fn modify_plugin_file(
|
||||
// Try to read the plugin file if it exists
|
||||
let mut contents = if fs::metadata(&plugin_registry_file_path).is_ok_and(|m| m.len() > 0) {
|
||||
PluginRegistryFile::read_from(
|
||||
File::open(&plugin_registry_file_path).map_err(|err| {
|
||||
IoError::new(err.kind(), file_span, plugin_registry_file_path.clone())
|
||||
})?,
|
||||
File::open(&plugin_registry_file_path)
|
||||
.map_err(|err| IoError::new(err, file_span, plugin_registry_file_path.clone()))?,
|
||||
Some(file_span),
|
||||
)?
|
||||
} else {
|
||||
@ -90,7 +93,7 @@ pub(crate) fn modify_plugin_file(
|
||||
// Save the modified file on success
|
||||
contents.write_to(
|
||||
File::create(&plugin_registry_file_path)
|
||||
.map_err(|err| IoError::new(err.kind(), file_span, plugin_registry_file_path))?,
|
||||
.map_err(|err| IoError::new(err, file_span, plugin_registry_file_path))?,
|
||||
Some(span),
|
||||
)?;
|
||||
|
||||
|
Reference in New Issue
Block a user