mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 10:03:24 +02:00
Convert Shellerror::GenericError
to named fields (#11230)
# Description Replace `.to_string()` used in `GenericError` with `.into()` as `.into()` seems more popular Replace `Vec::new()` used in `GenericError` with `vec![]` as `vec![]` seems more popular (There are so, so many)
This commit is contained in:
@@ -21,28 +21,28 @@ pub(super) fn process_string_enum<T, E>(
|
||||
*config_point = format;
|
||||
}
|
||||
Err(err) => {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
format!(
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: format!(
|
||||
"unrecognized $env.config.{} option '{v}'",
|
||||
config_path.join(".")
|
||||
),
|
||||
Some(span),
|
||||
Some(err.to_string()),
|
||||
vec![],
|
||||
));
|
||||
span: Some(span),
|
||||
help: Some(err.to_string()),
|
||||
inner: vec![],
|
||||
});
|
||||
// Reconstruct
|
||||
*value = config_point.reconstruct_value(span);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
format!("$env.config.{} should be a string", config_path.join(".")),
|
||||
Some(span),
|
||||
Some("This value will be ignored.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: format!("$env.config.{} should be a string", config_path.join(".")),
|
||||
span: Some(span),
|
||||
help: Some("This value will be ignored.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
// Reconstruct
|
||||
*value = config_point.reconstruct_value(span);
|
||||
}
|
||||
@@ -56,13 +56,13 @@ pub(super) fn process_bool_config(
|
||||
if let Ok(b) = value.as_bool() {
|
||||
*config_point = b;
|
||||
} else {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"should be a bool".to_string(),
|
||||
Some(value.span()),
|
||||
Some("This value will be ignored.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "should be a bool".to_string(),
|
||||
span: Some(value.span()),
|
||||
help: Some("This value will be ignored.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
// Reconstruct
|
||||
*value = Value::bool(*config_point, value.span());
|
||||
}
|
||||
@@ -76,13 +76,13 @@ pub(super) fn process_int_config(
|
||||
if let Ok(b) = value.as_int() {
|
||||
*config_point = b;
|
||||
} else {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"should be an int".to_string(),
|
||||
Some(value.span()),
|
||||
Some("This value will be ignored.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "should be an int".into(),
|
||||
span: Some(value.span()),
|
||||
help: Some("This value will be ignored.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
// Reconstruct
|
||||
*value = Value::int(*config_point, value.span());
|
||||
}
|
||||
@@ -92,26 +92,26 @@ pub(super) fn report_invalid_key(keys: &[&str], span: Span, errors: &mut Vec<She
|
||||
// Because Value::Record discards all of the spans of its
|
||||
// column names (by storing them as Strings), the key name cannot be provided
|
||||
// as a value, even in key errors.
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
format!(
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: format!(
|
||||
"$env.config.{} is an unknown config setting",
|
||||
keys.join(".")
|
||||
),
|
||||
Some(span),
|
||||
Some("This value will not appear in your $env.config record.".into()),
|
||||
vec![],
|
||||
));
|
||||
span: Some(span),
|
||||
help: Some("This value will not appear in your $env.config record.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn report_invalid_value(msg: &str, span: Span, errors: &mut Vec<ShellError>) {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
msg.into(),
|
||||
Some(span),
|
||||
Some("This value will be ignored.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: msg.into(),
|
||||
span: Some(span),
|
||||
help: Some("This value will be ignored.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn create_map(value: &Value) -> Result<HashMap<String, Value>, ShellError> {
|
||||
|
@@ -705,13 +705,13 @@ impl Value {
|
||||
} else {
|
||||
return (
|
||||
config,
|
||||
Some(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"$env.config is not a record".into(),
|
||||
Some(self.span()),
|
||||
None,
|
||||
vec![],
|
||||
)),
|
||||
Some(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "$env.config is not a record".into(),
|
||||
span: Some(self.span()),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -719,14 +719,13 @@ impl Value {
|
||||
(
|
||||
config,
|
||||
if !errors.is_empty() {
|
||||
Some(ShellError::GenericError(
|
||||
"Config record contains invalid values or unknown settings".into(),
|
||||
// Without a span, this second string is ignored.
|
||||
"".into(),
|
||||
None,
|
||||
None,
|
||||
errors,
|
||||
))
|
||||
Some(ShellError::GenericError {
|
||||
error: "Config record contains invalid values or unknown settings".into(),
|
||||
msg: "".into(),
|
||||
span: None,
|
||||
help: None,
|
||||
inner: errors,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
@@ -206,14 +206,12 @@ pub(super) fn try_parse_trim_strategy(
|
||||
value: &Value,
|
||||
errors: &mut Vec<ShellError>,
|
||||
) -> Result<TrimStrategy, ShellError> {
|
||||
let map = value.as_record().map_err(|e| {
|
||||
ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"$env.config.table.trim is not a record".into(),
|
||||
Some(value.span()),
|
||||
Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
vec![e],
|
||||
)
|
||||
let map = value.as_record().map_err(|e| ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "$env.config.table.trim is not a record".into(),
|
||||
span: Some(value.span()),
|
||||
help: Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
inner: vec![e],
|
||||
})?;
|
||||
|
||||
let mut methodology = match map.get("methodology") {
|
||||
@@ -222,13 +220,13 @@ pub(super) fn try_parse_trim_strategy(
|
||||
None => return Ok(TrimStrategy::default()),
|
||||
},
|
||||
None => {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"$env.config.table.trim.methodology was not provided".into(),
|
||||
Some(value.span()),
|
||||
Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "$env.config.table.trim.methodology was not provided".into(),
|
||||
span: Some(value.span()),
|
||||
help: Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
return Ok(TrimStrategy::default());
|
||||
}
|
||||
};
|
||||
@@ -239,13 +237,15 @@ pub(super) fn try_parse_trim_strategy(
|
||||
if let Ok(b) = value.as_bool() {
|
||||
*try_to_keep_words = b;
|
||||
} else {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"$env.config.table.trim.wrapping_try_keep_words is not a bool".into(),
|
||||
Some(value.span()),
|
||||
Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "$env.config.table.trim.wrapping_try_keep_words is not a bool".into(),
|
||||
span: Some(value.span()),
|
||||
help: Some(
|
||||
"Please consult the documentation for configuring Nushell.".into(),
|
||||
),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,13 +254,15 @@ pub(super) fn try_parse_trim_strategy(
|
||||
if let Ok(v) = value.as_string() {
|
||||
*suffix = Some(v);
|
||||
} else {
|
||||
errors.push(ShellError::GenericError(
|
||||
"Error while applying config changes".into(),
|
||||
"$env.config.table.trim.truncating_suffix is not a string".into(),
|
||||
Some(value.span()),
|
||||
Some("Please consult the documentation for configuring Nushell.".into()),
|
||||
vec![],
|
||||
));
|
||||
errors.push(ShellError::GenericError {
|
||||
error: "Error while applying config changes".into(),
|
||||
msg: "$env.config.table.trim.truncating_suffix is not a string".into(),
|
||||
span: Some(value.span()),
|
||||
help: Some(
|
||||
"Please consult the documentation for configuring Nushell.".into(),
|
||||
),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user