typed_env/
error.rs

1use crate::ErrorReason;
2use std::borrow::Cow;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum EnvarError {
7    #[error("Cannot parse environment variable {varname} (value = {value:?}) as {typename}")]
8    ParseError {
9        varname: Cow<'static, str>,
10        typename: &'static str,
11        value: String,
12        reason: ErrorReason,
13    },
14
15    #[error("Environment variable {0} is not set")]
16    NotSet(Cow<'static, str>),
17
18    // This is a special case:
19    // Sometimes even if the environment variable is set, we
20    // might prefer to use the default value (if any).
21    // For example, if the environment variable is set to an empty string,
22    // we might prefer to use the default value.
23    #[error("Environment variable {0} is not set and default factory returned None")]
24    TryDefault(Cow<'static, str>),
25}