composer_cli/errors/
io.rs1use super::*;
2
3#[derive(Error, Debug)]
4pub enum IOError {
5 PathNotFound,
6 Anyhow(Error),
7 Other(String),
8 Std(std::io::Error),
9}
10
11pub fn io_error(err: std::io::Error) -> Box<dyn Exception> {
12 Box::new(IOError::from(err))
13}
14
15impl Exception for IOError {
16 fn code(&self) -> i32 {
17 match self {
18 IOError::PathNotFound => 1,
19 IOError::Other(_) => 2,
20 IOError::Anyhow(_) => 3,
21 IOError::Std(_) => 4,
22 }
23 }
24}
25
26impl From<std::io::Error> for IOError {
27 fn from(value: std::io::Error) -> Self {
28 match value.kind() {
29 std::io::ErrorKind::NotFound => IOError::PathNotFound,
30 _ => IOError::Std(value),
31 }
32 }
33}
34
35impl Display for IOError {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 match self {
38 IOError::PathNotFound => write!(f, "PathNotFound"),
39 IOError::Anyhow(error) => write!(f, "{}", error),
40 IOError::Other(error) => write!(f, "{}", error),
41 IOError::Std(error) => write!(f, "{}", error),
42 }
43 }
44}