1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! User-facing error types.
//!
//! Although in theory [`UnexpectedSecret`] and [`MissingValue`] are also user facing, they are entirely
//! handled by the `derive` internals, so is counted as internal.

use std::error::Error as StdError;

use thiserror::Error;

use crate::{MissingValue, UnexpectedSecret};

/// Possible error values.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
    /// The value contained in the `path` was not found when attempting to build
    /// the [`Configuration`](crate::Configuration) in
    /// [`ConfigurationBuilder::try_build`](crate::ConfigurationBuilder::try_build).
    #[error(transparent)]
    MissingValue(#[from] MissingValue),

    /// A wrapper around the error from one of the sources.
    #[error("Source {1} returned an error")]
    Source(#[source] Box<dyn StdError + Send + Sync>, String),

    /// The value contained in the `path` was marked as a [`SecretBuilder`](crate::SecretBuilder) but
    /// was parsed from a [`Source`](crate::Source) that was not marked as a secret
    /// (see [`Source::allows_secrets`](crate::Source::allows_secrets)).
    #[error("Found a secret in source {1} that does not permit secrets")]
    UnexpectedSecret(#[source] UnexpectedSecret, String),
}