1use std::ffi::CString;
9use std::fmt;
10use std::io;
11use std::path::PathBuf;
12use std::str;
13
14use thiserror::Error;
15
16#[derive(Error, Debug)]
18pub enum Error {
19 #[error("{0}")]
21 Convert(String),
22
23 #[error("{0:?}:\n{1}")]
25 ParseFile(PathBuf, String),
26
27 #[error("malformed --config option: '{0}' (use --config section.name=value)")]
29 ParseFlag(String),
30
31 #[error("{0:?}: {1}")]
33 Io(PathBuf, #[source] io::Error),
34
35 #[error("{0:?}: {1}")]
37 Utf8(PathBuf, #[source] str::Utf8Error),
38
39 #[error("{0:?}: {1}")]
40 Utf8Path(CString, #[source] str::Utf8Error),
41
42 #[error(transparent)]
43 ParseInt(#[from] std::num::ParseIntError),
44
45 #[error(transparent)]
46 ParseFloat(#[from] std::num::ParseFloatError),
47
48 #[error("{0}")]
49 General(String),
50
51 #[error("config {0}.{1} is not set")]
52 NotSet(String, String),
53
54 #[error("{0}")]
55 Other(#[source] anyhow::Error),
56}
57
58impl From<String> for Error {
59 fn from(s: String) -> Self {
60 Self::General(s)
61 }
62}
63
64#[derive(Error, Debug)]
65pub struct Errors(pub Vec<Error>);
66
67impl fmt::Display for Errors {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 for error in self.0.iter() {
70 write!(f, "{}\n", error)?;
71 }
72 Ok(())
73 }
74}