1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SdfError>;
4
5#[derive(Debug, Error)]
6#[error(transparent)]
7pub struct SdfError(#[from] ErrorKind);
8
9#[derive(Debug, Error)]
10pub(crate) enum ErrorKind {
11 #[error(transparent)]
12 File(#[from] std::io::Error),
13 #[error(transparent)]
14 Xml(#[from] serde_xml_rs::Error),
15 #[error(transparent)]
16 RustyXml(#[from] xml::BuilderError),
17 #[error("command error {}", .0)]
18 Command(String),
19}
20
21impl SdfError {
22 pub(crate) fn new(err: impl Into<ErrorKind>) -> Self {
23 Self(err.into())
24 }
25}
26
27impl From<std::io::Error> for SdfError {
28 fn from(err: std::io::Error) -> SdfError {
29 ErrorKind::File(err).into()
30 }
31}
32
33impl From<&str> for SdfError {
34 fn from(err: &str) -> SdfError {
35 ErrorKind::Command(err.to_owned()).into()
36 }
37}
38
39impl From<std::string::FromUtf8Error> for SdfError {
40 fn from(err: std::string::FromUtf8Error) -> SdfError {
41 ErrorKind::Command(err.to_string()).into()
42 }
43}