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:
Eric Hodel
2023-11-21 15:30:21 -08:00
committed by GitHub
parent 5ad7b8f029
commit e36f69bf3c
6 changed files with 49 additions and 39 deletions

View File

@ -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,
));
});
}
}
}

View File

@ -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) {