use std::{borrow::Cow, error::Error as StdError};
use thiserror::Error;
use crate::{FailedTryInto, MissingValue, UnexpectedSecret};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
MissingValue(#[from] MissingValue),
#[error("Source {1} returned an error")]
Source(#[source] Box<dyn StdError + Send + Sync>, String),
#[error("Found a secret in source {1} that does not permit secrets")]
UnexpectedSecret(#[source] UnexpectedSecret, String),
#[error(transparent)]
TryInto(#[from] FailedTryInto),
}
impl Error {
#[doc(hidden)]
#[must_use]
pub fn prepend(self, path_segment: impl Into<Cow<'static, str>>) -> Self {
match self {
Self::MissingValue(err) => Self::MissingValue(err.prepend(path_segment)),
Self::TryInto(err) => Self::TryInto(err.prepend(path_segment)),
Self::UnexpectedSecret(err, source) => {
Self::UnexpectedSecret(err.prepend(path_segment), source)
}
Self::Source(err, source) => Self::Source(err, source),
}
}
}