Refactor: Construct IoError from std::io::Error instead of std::io::ErrorKind (#15777)

This commit is contained in:
Piepmatz
2025-05-18 14:52:40 +02:00
committed by GitHub
parent c4dcfdb77b
commit 833471241a
80 changed files with 408 additions and 299 deletions

View File

@ -4,7 +4,7 @@ use nu_protocol::{
ShellError, Span, Type, Value, VarId,
ast::Expr,
engine::{Call, EngineState, Stack, StateWorkingSet},
shell_error::io::{ErrorKindExt, IoError, NotFound},
shell_error::io::{IoError, IoErrorExt, NotFound},
};
use std::{
collections::HashMap,
@ -221,7 +221,7 @@ pub fn current_dir(engine_state: &EngineState, stack: &Stack) -> Result<PathBuf,
// be an absolute path already.
canonicalize_with(&cwd, ".").map_err(|err| {
ShellError::Io(IoError::new_internal_with_path(
err.kind().not_found_as(NotFound::Directory),
err.not_found_as(NotFound::Directory),
"Could not canonicalize current dir",
nu_protocol::location!(),
PathBuf::from(cwd),
@ -241,7 +241,7 @@ pub fn current_dir_const(working_set: &StateWorkingSet) -> Result<PathBuf, Shell
// be an absolute path already.
canonicalize_with(&cwd, ".").map_err(|err| {
ShellError::Io(IoError::new_internal_with_path(
err.kind().not_found_as(NotFound::Directory),
err.not_found_as(NotFound::Directory),
"Could not canonicalize current dir",
nu_protocol::location!(),
PathBuf::from(cwd),

View File

@ -1529,7 +1529,7 @@ fn open_file(ctx: &EvalContext<'_>, path: &Value, append: bool) -> Result<Arc<Fi
let file = options
.create(true)
.open(&path_expanded)
.map_err(|err| IoError::new(err.kind(), path.span(), path_expanded))?;
.map_err(|err| IoError::new(err, path.span(), path_expanded))?;
Ok(Arc::new(file))
}

View File

@ -81,7 +81,7 @@ pub fn glob_from(
}
Ok(p) => p,
Err(err) => {
return Err(IoError::new(err.kind(), pattern_span, path).into());
return Err(IoError::new(err, pattern_span, path).into());
}
};
(path.parent().map(|parent| parent.to_path_buf()), path)