pub struct ConfigError {
pub problems: Vec<String>,
/* private fields */
}Expand description
An enabled config that cannot be used, with every problem found.
Display renders all of them under one header naming the block the way
KeyNaming spells it; for Dotted("mcp.oauth") that is
mcp.oauth.enabled is true but the OAuth config is not usable:
- <problem>
- <problem>
Fix these, or set mcp.oauth.enabled: false.Each problem is available two ways.
problem_details is the structured list
(ConfigProblem: a ProblemKind, the settings named, the message); the
public problems field holds the same messages as plain
strings, kept for compatibility. Prefer matching on ProblemKind to
matching text: message wording is not a stable API.
Fields§
§problems: Vec<String>One human-readable sentence per problem, each naming its setting.
Kept for compatibility; the structured form is
problem_details. Both are filled from one
list at construction, in the same order. Editing this field in place
does not update problem_details(); Display renders this field.
Implementations§
Source§impl ConfigError
impl ConfigError
Sourcepub fn new(naming: KeyNaming<'_>, problems: Vec<String>) -> Self
pub fn new(naming: KeyNaming<'_>, problems: Vec<String>) -> Self
An error listing problems, whose header names settings per naming.
For loaders that add their own problems (parse errors, say) alongside the
ones OAuthConfig::resolve finds. Each string becomes a
ProblemKind::Other problem in
problem_details; use
from_problems to give them kinds.
problems must not be empty: an error with nothing to fix would display
as a header over one blank bullet. Debug builds assert it.
Sourcepub fn from_problems(
naming: KeyNaming<'_>,
problems: impl IntoIterator<Item = ConfigProblem>,
) -> Self
pub fn from_problems( naming: KeyNaming<'_>, problems: impl IntoIterator<Item = ConfigProblem>, ) -> Self
An error listing structured problems, whose header names settings per
naming. problems is rendered from their messages,
so the two views agree. A String converts with .into() (kind
ProblemKind::Other), so an application loader can mix its own
problems in with the crate’s.
problems must not be empty; debug builds assert it.
Sourcepub fn problem_details(&self) -> &[ConfigProblem]
pub fn problem_details(&self) -> &[ConfigProblem]
The structured problems, in the order problems lists
them. Match on ProblemKind rather than on message text:
use oauth_resource_server::{KeyNaming, OAuthConfig, ProblemKind};
let err = OAuthConfig {
enabled: true,
leeway_secs: 3600,
..OAuthConfig::default()
}
.resolve(KeyNaming::Env("MYAPP_OAUTH_"))
.unwrap_err();
for problem in err.problem_details() {
match problem.kind() {
ProblemKind::MissingRequired => {
assert!(problem.keys().contains(&"MYAPP_OAUTH_ISSUER".to_string()));
}
ProblemKind::LeewayTooLarge => {
assert_eq!(problem.keys(), ["MYAPP_OAUTH_LEEWAY_SECS"]);
}
// `ProblemKind` is `#[non_exhaustive]`: keep a wildcard arm.
_ => {}
}
}An error built with ConfigError::new reports every problem as
ProblemKind::Other. The list is fixed at construction: editing the
public problems field in place does not change it (that field is kept
for compatibility).
Trait Implementations§
Source§impl Clone for ConfigError
impl Clone for ConfigError
Source§impl Debug for ConfigError
impl Debug for ConfigError
Source§impl Display for ConfigError
impl Display for ConfigError
impl Eq for ConfigError
Source§impl Error for ConfigError
impl Error for ConfigError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for ConfigError
Equality is over problems and the naming only,
as before structured details existed: an error rebuilt with
ConfigError::new from another’s problems compares equal to it.
impl PartialEq for ConfigError
Equality is over problems and the naming only,
as before structured details existed: an error rebuilt with
ConfigError::new from another’s problems compares equal to it.