pub enum Error {
Missing {
name: String,
},
Invalid {
name: String,
expected: String,
got: String,
},
Conflict {
message: String,
},
}Expand description
One thing wrong with one variable.
Each variant names the variable, because the first thing anyone does with a configuration error is search the deployment for that name.
Variants§
Missing
A required variable is unset or blank.
Invalid
A variable is set to something that is not the shape it must be.
Fields
got: StringWhat was there.
Quoted in the message. Configuration values are operational
rather than sensitive — and the one kind that is not should be
read through crate::Secret, which never reaches this type.
Conflict
Two or more variables are individually fine but cannot be combined.
Implementations§
Source§impl Error
impl Error
Sourcepub fn missing(name: impl Into<String>) -> Self
pub fn missing(name: impl Into<String>) -> Self
A required variable is unset or blank.
§Examples
use env_reader::Error;
let error = Error::missing("DATABASE_URL");
assert_eq!(error.to_string(), "missing required configuration: DATABASE_URL");Sourcepub fn invalid(
name: impl Into<String>,
expected: impl Into<String>,
got: impl Into<String>,
) -> Self
pub fn invalid( name: impl Into<String>, expected: impl Into<String>, got: impl Into<String>, ) -> Self
A variable holds something of the wrong shape.
§Examples
use env_reader::Error;
let error = Error::invalid("PORT", "a whole number", "two");
assert_eq!(
error.to_string(),
r#"invalid configuration: PORT must be a whole number, got "two""#
);Sourcepub fn conflict(message: impl Into<String>) -> Self
pub fn conflict(message: impl Into<String>) -> Self
Variables that cannot be combined as configured.
§Examples
use env_reader::Error;
let error = Error::conflict("Cannot specify both QUEUE_NAME and TOPIC_NAME.");
assert!(error.to_string().starts_with("Cannot specify both"));Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
The variable this is about, when it is about one.
Error::Conflict concerns a relationship between variables and so
names none.
§Examples
use env_reader::Error;
assert_eq!(Error::missing("PORT").name(), Some("PORT"));
assert_eq!(Error::conflict("either, not both").name(), None);Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
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()