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

@@ -1,5 +1,8 @@
use nu_engine::command_prelude::*;
use nu_protocol::{HistoryFileFormat, shell_error::io::IoError};
use nu_protocol::{
HistoryFileFormat,
shell_error::{self, io::IoError},
};
use reedline::{
FileBackedHistory, History as ReedlineHistory, HistoryItem, SearchDirection, SearchQuery,
SqliteBackedHistory,
@@ -94,7 +97,7 @@ impl Command for History {
})
})
.ok_or(IoError::new(
std::io::ErrorKind::NotFound,
shell_error::io::ErrorKind::FileNotFound,
head,
history_path,
))?
@@ -110,7 +113,7 @@ impl Command for History {
})
})
.ok_or(IoError::new(
std::io::ErrorKind::NotFound,
shell_error::io::ErrorKind::FileNotFound,
head,
history_path,
))?

View File

@@ -287,7 +287,7 @@ fn backup(path: &Path, span: Span) -> Result<Option<PathBuf>, ShellError> {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
Err(e) => {
return Err(IoError::new_internal(
e.kind(),
e,
"Could not get metadata",
nu_protocol::location!(),
)
@@ -297,7 +297,7 @@ fn backup(path: &Path, span: Span) -> Result<Option<PathBuf>, ShellError> {
let bak_path = find_backup_path(path, span)?;
std::fs::copy(path, &bak_path).map_err(|err| {
IoError::new_internal(
err.kind(),
err.not_found_as(NotFound::File),
"Could not copy backup",
nu_protocol::location!(),
)

View File

@@ -42,7 +42,7 @@ impl Command for KeybindingsListen {
Err(e) => {
terminal::disable_raw_mode().map_err(|err| {
IoError::new_internal(
err.kind(),
err,
"Could not disable raw mode",
nu_protocol::location!(),
)
@@ -71,18 +71,10 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
let config = engine_state.get_config();
stdout().flush().map_err(|err| {
IoError::new_internal(
err.kind(),
"Could not flush stdout",
nu_protocol::location!(),
)
IoError::new_internal(err, "Could not flush stdout", nu_protocol::location!())
})?;
terminal::enable_raw_mode().map_err(|err| {
IoError::new_internal(
err.kind(),
"Could not enable raw mode",
nu_protocol::location!(),
)
IoError::new_internal(err, "Could not enable raw mode", nu_protocol::location!())
})?;
if config.use_kitty_protocol {
@@ -114,7 +106,7 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
loop {
let event = crossterm::event::read().map_err(|err| {
IoError::new_internal(err.kind(), "Could not read event", nu_protocol::location!())
IoError::new_internal(err, "Could not read event", nu_protocol::location!())
})?;
if event == Event::Key(KeyCode::Esc.into()) {
break;
@@ -136,7 +128,7 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
};
stdout.queue(crossterm::style::Print(o)).map_err(|err| {
IoError::new_internal(
err.kind(),
err,
"Could not print output record",
nu_protocol::location!(),
)
@@ -144,14 +136,10 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
stdout
.queue(crossterm::style::Print("\r\n"))
.map_err(|err| {
IoError::new_internal(
err.kind(),
"Could not print linebreak",
nu_protocol::location!(),
)
IoError::new_internal(err, "Could not print linebreak", nu_protocol::location!())
})?;
stdout.flush().map_err(|err| {
IoError::new_internal(err.kind(), "Could not flush", nu_protocol::location!())
IoError::new_internal(err, "Could not flush", nu_protocol::location!())
})?;
}
@@ -163,11 +151,7 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
}
terminal::disable_raw_mode().map_err(|err| {
IoError::new_internal(
err.kind(),
"Could not disable raw mode",
nu_protocol::location!(),
)
IoError::new_internal(err, "Could not disable raw mode", nu_protocol::location!())
})?;
Ok(Value::nothing(Span::unknown()))