use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("IO error: `{0}`")]
IoError(#[from] std::io::Error),
#[error("TOML parsing error: `{0}`")]
TomlError(#[from] toml::de::Error),
#[error("Request error: `{0}`")]
RequestError(#[from] Box<ureq::Error>),
#[error("Unsupported platform.")]
UnsupportedPlatformError,
#[error("TOML serialization error: `{0}`")]
TomlSerializeError(#[from] toml::ser::Error),
#[error("External help provider error: `{0}`")]
ProviderError(String),
#[error("Dialogue error: `{0}`")]
DialogueError(#[from] dialoguer::Error),
#[error("Command timed out after {0} seconds x_x")]
TimeoutError(u64),
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use std::io::{Error as IoError, ErrorKind};
#[test]
fn test_error() {
let message = "your computer is on fire!";
let error = Error::from(IoError::new(ErrorKind::Other, message));
assert_eq!(format!("IO error: `{message}`"), error.to_string());
assert_eq!(
format!("\"IO error: `{message}`\""),
format!("{:?}", error.to_string())
);
}
}