credence_lib/configuration/
error.rs

1use {
2    compris::{annotate::*, resolve::*},
3    kutil::{cli::depict::*, http::tls::*},
4    std::io,
5    thiserror::*,
6};
7
8//
9// ConfigurationError
10//
11
12/// Configuration error.
13#[derive(Debug, Error)]
14pub enum ConfigurationError {
15    /// None.
16    #[error("no configuration")]
17    None,
18
19    /// I/O.
20    #[error("I/O: {0}")]
21    IO(#[from] io::Error),
22
23    /// TLS.
24    #[error("TLS: {0}")]
25    TLS(#[from] TlsContainerError),
26
27    /// Notify.
28    #[error("notify: {0}")]
29    Notify(#[from] notify::Error),
30
31    /// Validation.
32    #[error("validation: {0}")]
33    Validation(ResolveErrors<WithAnnotations>),
34}
35
36impl ConfigurationError {
37    /// Prints validation errors.
38    pub fn eprint_validation_errors(&self) -> bool {
39        match self {
40            Self::Validation(errors) => {
41                errors.annotated_depictions(Some("Invalid CredenceConfiguration".into())).eprint_default_depiction();
42                true
43            }
44
45            _ => false,
46        }
47    }
48}
49
50impl From<ResolveErrors<WithAnnotations>> for ConfigurationError {
51    fn from(errors: ResolveErrors<WithAnnotations>) -> Self {
52        Self::Validation(errors)
53    }
54}
55
56impl From<String> for ConfigurationError {
57    fn from(message: String) -> Self {
58        let error: ResolveError<_> = message.into();
59        Self::Validation(error.into())
60    }
61}
62
63impl From<&str> for ConfigurationError {
64    fn from(message: &str) -> Self {
65        String::from(message).into()
66    }
67}