1mod tools;
2
3use std::fmt;
4use std::io;
5
6#[derive(Debug)]
9pub struct Error {
10 inner: Box<ErrorKind>,
11}
12
13#[derive(Debug, thiserror::Error)]
16enum ErrorKind {
17 #[error(transparent)]
18 Tools(#[from] tools::ToolError),
19}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "{}", self.inner)
24 }
25}
26
27impl std::error::Error for Error {
28 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
29 self.inner.source()
30 }
31}
32
33impl Error {
34 pub fn tool_io(err: io::Error) -> Self {
36 Error {
37 inner: Box::new(ErrorKind::Tools(tools::ToolError::Io(err))),
38 }
39 }
40
41 pub fn tool_cmd_failed(code: i32) -> Self {
43 Error {
44 inner: Box::new(ErrorKind::Tools(tools::ToolError::CommandFailed(code))),
45 }
46 }
47
48 pub fn tool_timeout() -> Self {
50 Error {
51 inner: Box::new(ErrorKind::Tools(tools::ToolError::Timeout)),
52 }
53 }
54}
55
56pub type Result<T> = std::result::Result<T, Error>;