forked from extern/nushell
More precise ErrorKind::NotFound
errors (#15149)
In this PR, the two new variants for `ErrorKind`, `FileNotFound` and `DirectoryNotFound` with a nice `not_found_as` method for the `ErrorKind` to easily specify the `NotFound` errors. I also updated some places where I could of think of with these new variants and the message for `NotFound` is no longer "Entity not found" but "Not found" to be less strange. closes #15142 closes #15055
This commit is contained in:
10
crates/nu-command/src/env/config/config_reset.rs
vendored
10
crates/nu-command/src/env/config/config_reset.rs
vendored
@ -1,7 +1,5 @@
|
||||
use chrono::Local;
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_protocol::shell_error::io::IoError;
|
||||
use nu_utils::{get_scaffold_config, get_scaffold_env};
|
||||
use std::{io::Write, path::PathBuf};
|
||||
|
||||
@ -61,7 +59,7 @@ impl Command for ConfigReset {
|
||||
));
|
||||
if let Err(err) = std::fs::rename(nu_config.clone(), &backup_path) {
|
||||
return Err(ShellError::Io(IoError::new_with_additional_context(
|
||||
err.kind(),
|
||||
err.kind().not_found_as(NotFound::Directory),
|
||||
span,
|
||||
PathBuf::from(backup_path),
|
||||
"config.nu could not be backed up",
|
||||
@ -71,7 +69,7 @@ impl Command for ConfigReset {
|
||||
if let Ok(mut file) = std::fs::File::create(&nu_config) {
|
||||
if let Err(err) = writeln!(&mut file, "{config_file}") {
|
||||
return Err(ShellError::Io(IoError::new_with_additional_context(
|
||||
err.kind(),
|
||||
err.kind().not_found_as(NotFound::File),
|
||||
span,
|
||||
PathBuf::from(nu_config),
|
||||
"config.nu could not be written to",
|
||||
@ -88,7 +86,7 @@ impl Command for ConfigReset {
|
||||
backup_path.push(format!("oldenv-{}.nu", Local::now().format("%F-%H-%M-%S"),));
|
||||
if let Err(err) = std::fs::rename(env_config.clone(), &backup_path) {
|
||||
return Err(ShellError::Io(IoError::new_with_additional_context(
|
||||
err.kind(),
|
||||
err.kind().not_found_as(NotFound::Directory),
|
||||
span,
|
||||
PathBuf::from(backup_path),
|
||||
"env.nu could not be backed up",
|
||||
@ -98,7 +96,7 @@ impl Command for ConfigReset {
|
||||
if let Ok(mut file) = std::fs::File::create(&env_config) {
|
||||
if let Err(err) = writeln!(&mut file, "{config_file}") {
|
||||
return Err(ShellError::Io(IoError::new_with_additional_context(
|
||||
err.kind(),
|
||||
err.kind().not_found_as(NotFound::File),
|
||||
span,
|
||||
PathBuf::from(env_config),
|
||||
"env.nu could not be written to",
|
||||
|
Reference in New Issue
Block a user