Refactor config updates (#13802)

# Description
This PR standardizes updates to the config through a new
`UpdateFromValue` trait. For now, this trait is private in case we need
to make changes to it.

Note that this PR adds some additional `ShellError` cases to create
standard error messages for config errors. A follow-up PR will move
usages of the old error cases to these new ones. This PR also uses
`Type::custom` in lots of places (e.g., for string enums). Not sure if
this is something we want to encourage.

# User-Facing Changes
Should be none.
This commit is contained in:
Ian Manske
2024-10-11 09:40:32 -07:00
committed by GitHub
parent 02313e6819
commit fce6146576
32 changed files with 1343 additions and 1487 deletions

View File

@ -300,14 +300,14 @@ impl UrlComponents {
return Ok(true);
}
match key {
"host" => Err(ShellError::UnsupportedConfigValue {
expected: "non-empty string".into(),
value: "empty string".into(),
"host" => Err(ShellError::InvalidValue {
valid: "a non-empty string".into(),
actual: format!("'{s}'"),
span: value_span,
}),
"scheme" => Err(ShellError::UnsupportedConfigValue {
expected: "non-empty string".into(),
value: "empty string".into(),
"scheme" => Err(ShellError::InvalidValue {
valid: "a non-empty string".into(),
actual: format!("'{s}'"),
span: value_span,
}),
_ => Ok(false),