forked from extern/nushell
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:
parent
5ad7b8f029
commit
e36f69bf3c
crates
nu-cli/src
nu-cmd-dataframe/src/dataframe/eager
nu-command/src
nu-protocol/src
src
@ -35,10 +35,10 @@ pub fn evaluate_file(
|
|||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(
|
report_error(
|
||||||
&working_set,
|
&working_set,
|
||||||
&ShellError::FileNotFoundCustom(
|
&ShellError::FileNotFoundCustom {
|
||||||
format!("Could not access file '{}': {:?}", path, e.to_string()),
|
msg: format!("Could not access file '{}': {:?}", path, e.to_string()),
|
||||||
Span::unknown(),
|
span: Span::unknown(),
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
});
|
});
|
||||||
@ -64,14 +64,14 @@ pub fn evaluate_file(
|
|||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(
|
report_error(
|
||||||
&working_set,
|
&working_set,
|
||||||
&ShellError::FileNotFoundCustom(
|
&ShellError::FileNotFoundCustom {
|
||||||
format!(
|
msg: format!(
|
||||||
"Could not read file '{}': {:?}",
|
"Could not read file '{}': {:?}",
|
||||||
file_path_str,
|
file_path_str,
|
||||||
e.to_string()
|
e.to_string()
|
||||||
),
|
),
|
||||||
Span::unknown(),
|
span: Span::unknown(),
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
});
|
});
|
||||||
@ -82,10 +82,10 @@ pub fn evaluate_file(
|
|||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(
|
report_error(
|
||||||
&working_set,
|
&working_set,
|
||||||
&ShellError::FileNotFoundCustom(
|
&ShellError::FileNotFoundCustom {
|
||||||
format!("The file path '{file_path_str}' does not have a parent"),
|
msg: format!("The file path '{file_path_str}' does not have a parent"),
|
||||||
Span::unknown(),
|
span: Span::unknown(),
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
});
|
});
|
||||||
|
@ -121,15 +121,15 @@ fn command(
|
|||||||
"json" => from_json(engine_state, stack, call),
|
"json" => from_json(engine_state, stack, call),
|
||||||
"jsonl" => from_jsonl(engine_state, stack, call),
|
"jsonl" => from_jsonl(engine_state, stack, call),
|
||||||
"avro" => from_avro(engine_state, stack, call),
|
"avro" => from_avro(engine_state, stack, call),
|
||||||
_ => Err(ShellError::FileNotFoundCustom(
|
_ => Err(ShellError::FileNotFoundCustom {
|
||||||
format!("{msg}. Supported values: csv, tsv, parquet, ipc, arrow, json"),
|
msg: format!("{msg}. Supported values: csv, tsv, parquet, ipc, arrow, json"),
|
||||||
blamed,
|
span: blamed,
|
||||||
)),
|
}),
|
||||||
},
|
},
|
||||||
None => Err(ShellError::FileNotFoundCustom(
|
None => Err(ShellError::FileNotFoundCustom {
|
||||||
"File without extension".into(),
|
msg: "File without extension".into(),
|
||||||
file.span,
|
span: file.span,
|
||||||
)),
|
}),
|
||||||
}
|
}
|
||||||
.map(|value| PipelineData::Value(value, None))
|
.map(|value| PipelineData::Value(value, None))
|
||||||
}
|
}
|
||||||
|
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"),
|
Local::now().format("%F-%H-%M-%S"),
|
||||||
));
|
));
|
||||||
if std::fs::rename(nu_config.clone(), backup_path).is_err() {
|
if std::fs::rename(nu_config.clone(), backup_path).is_err() {
|
||||||
return Err(ShellError::FileNotFoundCustom(
|
return Err(ShellError::FileNotFoundCustom {
|
||||||
"config.nu could not be backed up".into(),
|
msg: "config.nu could not be backed up".into(),
|
||||||
span,
|
span,
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(mut file) = std::fs::File::create(nu_config) {
|
if let Ok(mut file) = std::fs::File::create(nu_config) {
|
||||||
if writeln!(&mut file, "{config_file}").is_err() {
|
if writeln!(&mut file, "{config_file}").is_err() {
|
||||||
return Err(ShellError::FileNotFoundCustom(
|
return Err(ShellError::FileNotFoundCustom {
|
||||||
"config.nu could not be written to".into(),
|
msg: "config.nu could not be written to".into(),
|
||||||
span,
|
span,
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,18 +95,18 @@ impl Command for ConfigReset {
|
|||||||
let mut backup_path = config_path.clone();
|
let mut backup_path = config_path.clone();
|
||||||
backup_path.push(format!("oldenv-{}.nu", Local::now().format("%F-%H-%M-%S"),));
|
backup_path.push(format!("oldenv-{}.nu", Local::now().format("%F-%H-%M-%S"),));
|
||||||
if std::fs::rename(env_config.clone(), backup_path).is_err() {
|
if std::fs::rename(env_config.clone(), backup_path).is_err() {
|
||||||
return Err(ShellError::FileNotFoundCustom(
|
return Err(ShellError::FileNotFoundCustom {
|
||||||
"env.nu could not be backed up".into(),
|
msg: "env.nu could not be backed up".into(),
|
||||||
span,
|
span,
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(mut file) = std::fs::File::create(env_config) {
|
if let Ok(mut file) = std::fs::File::create(env_config) {
|
||||||
if writeln!(&mut file, "{config_file}").is_err() {
|
if writeln!(&mut file, "{config_file}").is_err() {
|
||||||
return Err(ShellError::FileNotFoundCustom(
|
return Err(ShellError::FileNotFoundCustom {
|
||||||
"env.nu could not be written to".into(),
|
msg: "env.nu could not be written to".into(),
|
||||||
span,
|
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() {
|
let shell_error = match error.kind() {
|
||||||
ErrorKind::NotFound => {
|
ErrorKind::NotFound => {
|
||||||
if std::path::Path::new(&dst).exists() {
|
if std::path::Path::new(&dst).exists() {
|
||||||
ShellError::FileNotFoundCustom(message_src, span)
|
ShellError::FileNotFoundCustom {
|
||||||
|
msg: message_src,
|
||||||
|
span,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ShellError::FileNotFoundCustom(message_dst, span)
|
ShellError::FileNotFoundCustom {
|
||||||
|
msg: message_dst,
|
||||||
|
span,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ErrorKind::PermissionDenied => match std::fs::metadata(&dst) {
|
ErrorKind::PermissionDenied => match std::fs::metadata(&dst) {
|
||||||
|
@ -725,7 +725,11 @@ pub enum ShellError {
|
|||||||
/// Does the file in the error message exist? Is it readable and accessible? Is the casing right?
|
/// Does the file in the error message exist? Is it readable and accessible? Is the casing right?
|
||||||
#[error("File not found")]
|
#[error("File not found")]
|
||||||
#[diagnostic(code(nu::shell::file_not_found))]
|
#[diagnostic(code(nu::shell::file_not_found))]
|
||||||
FileNotFoundCustom(String, #[label("{0}")] Span),
|
FileNotFoundCustom {
|
||||||
|
msg: String,
|
||||||
|
#[label("{msg}")]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
|
||||||
/// A plugin failed to load.
|
/// A plugin failed to load.
|
||||||
///
|
///
|
||||||
|
@ -59,10 +59,10 @@ fn read_in_file<'a>(
|
|||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(
|
report_error(
|
||||||
&working_set,
|
&working_set,
|
||||||
&ShellError::FileNotFoundCustom(
|
&ShellError::FileNotFoundCustom {
|
||||||
format!("Could not read file '{}': {:?}", file_path, e.to_string()),
|
msg: format!("Could not read file '{}': {:?}", file_path, e.to_string()),
|
||||||
Span::unknown(),
|
span: Span::unknown(),
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user