mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Convert FileNotFoundCustom to named fields (#11123)
# Description Part of #10700 # User-Facing Changes None # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A
This commit is contained in:
24
crates/nu-command/src/env/config/config_reset.rs
vendored
24
crates/nu-command/src/env/config/config_reset.rs
vendored
@ -72,18 +72,18 @@ impl Command for ConfigReset {
|
||||
Local::now().format("%F-%H-%M-%S"),
|
||||
));
|
||||
if std::fs::rename(nu_config.clone(), backup_path).is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"config.nu could not be backed up".into(),
|
||||
return Err(ShellError::FileNotFoundCustom {
|
||||
msg: "config.nu could not be backed up".into(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Ok(mut file) = std::fs::File::create(nu_config) {
|
||||
if writeln!(&mut file, "{config_file}").is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"config.nu could not be written to".into(),
|
||||
return Err(ShellError::FileNotFoundCustom {
|
||||
msg: "config.nu could not be written to".into(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,18 +95,18 @@ impl Command for ConfigReset {
|
||||
let mut backup_path = config_path.clone();
|
||||
backup_path.push(format!("oldenv-{}.nu", Local::now().format("%F-%H-%M-%S"),));
|
||||
if std::fs::rename(env_config.clone(), backup_path).is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"env.nu could not be backed up".into(),
|
||||
return Err(ShellError::FileNotFoundCustom {
|
||||
msg: "env.nu could not be backed up".into(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Ok(mut file) = std::fs::File::create(env_config) {
|
||||
if writeln!(&mut file, "{config_file}").is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"env.nu could not be written to".into(),
|
||||
return Err(ShellError::FileNotFoundCustom {
|
||||
msg: "env.nu could not be written to".into(),
|
||||
span,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -563,9 +563,15 @@ fn convert_io_error(error: std::io::Error, src: PathBuf, dst: PathBuf, span: Spa
|
||||
let shell_error = match error.kind() {
|
||||
ErrorKind::NotFound => {
|
||||
if std::path::Path::new(&dst).exists() {
|
||||
ShellError::FileNotFoundCustom(message_src, span)
|
||||
ShellError::FileNotFoundCustom {
|
||||
msg: message_src,
|
||||
span,
|
||||
}
|
||||
} else {
|
||||
ShellError::FileNotFoundCustom(message_dst, span)
|
||||
ShellError::FileNotFoundCustom {
|
||||
msg: message_dst,
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
ErrorKind::PermissionDenied => match std::fs::metadata(&dst) {
|
||||
|
Reference in New Issue
Block a user