credence_lib/configuration/
error.rs1use {
2 compris::{annotate::*, resolve::*},
3 kutil::{cli::depict::*, http::tls::*},
4 std::io,
5 thiserror::*,
6};
7
8#[derive(Debug, Error)]
14pub enum ConfigurationError {
15 #[error("no configuration")]
17 None,
18
19 #[error("I/O: {0}")]
21 IO(#[from] io::Error),
22
23 #[error("TLS: {0}")]
25 TLS(#[from] TlsContainerError),
26
27 #[error("notify: {0}")]
29 Notify(#[from] notify::Error),
30
31 #[error("validation: {0}")]
33 Validation(ResolveErrors<WithAnnotations>),
34}
35
36impl ConfigurationError {
37 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}