1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Errors that can be generated by the Process Foundry
//!
//! We rewrap all the modules errors so the end coder can catch a fully enumerated list of errors

use serde_derive::{Deserialize, Serialize};
use thiserror::Error;

#[derive(Debug, Clone, Error, Deserialize, Serialize)]
pub enum FoundryError {
  #[error("There was an error attempting to convert from one type to another")]
  ConversionError,

  #[error("The application has a problem with the configuration")]
  ConfigurationError,

  #[error("This item's key is already in use")]
  DuplicateKeyError,

  #[error("There was a problem with the file")]
  IoError,

  #[error("Received multiple instances when looking for a single unique response")]
  MultipleMatches,

  #[error("The app has not been configured for the action you are trying to run")]
  NotConfigured,

  #[error("The item you were looking for was not found")]
  NotFound,

  #[error("The command sent to the container caused an error")]
  RemoteError,

  #[error("The value received doesn't appear to match the expected format")]
  UnexpectedValue,

  #[error("We received an error that was not explicitly handled")]
  UnhandledError,

  #[error("Got to a surprise option in a match statement")]
  Unreachable,

  #[error("Trouble with a Yaml configuration")]
  YamlError,
}

impl From<std::num::ParseIntError> for FoundryError {
  fn from(err: std::num::ParseIntError) -> FoundryError {
    log::warn!("Received Parse Int Error:\n{:#?}", err);
    FoundryError::ConversionError
  }
}

impl From<std::num::ParseFloatError> for FoundryError {
  fn from(err: std::num::ParseFloatError) -> FoundryError {
    log::warn!("Received Parse Float Error:\n{:#?}", err);
    FoundryError::ConversionError
  }
}

impl From<std::string::FromUtf8Error> for FoundryError {
  fn from(err: std::string::FromUtf8Error) -> FoundryError {
    log::warn!(
      "Received Error converting from utf8 into a String:\n{:#?}",
      err
    );
    FoundryError::ConversionError
  }
}

// impl From<std::io::Error> for FoundryError {
//   fn from(err: std::io::Error) -> FoundryError {
//     FoundryError::new(ErrorKind::IOError, err.to_string())
//       .add_original_type("std::io::Error".to_string())
//   }
// }

// impl From<semver::ReqParseError> for FoundryError {
//   fn from(err: semver::ReqParseError) -> FoundryError {
//     FoundryError::new(ErrorKind::ParsingError, err.to_string())
//       .add_original_type("semver::ReqParseError".to_string())
//   }
// }

// impl From<semver::SemVerError> for FoundryError {
//   fn from(err: semver::SemVerError) -> FoundryError {
//     FoundryError::new(ErrorKind::ParsingError, err.to_string())
//       .add_original_type("semver::SemVerError".to_string())
//   }
// }