Skip to main content

rom_core/
error.rs

1//! Error types for ROM
2
3use std::io;
4
5use thiserror::Error;
6
7/// Result type for ROM operations
8pub type Result<T> = std::result::Result<T, RomError>;
9
10/// Main error type for ROM
11#[derive(Debug, Error)]
12pub enum RomError {
13  /// IO error
14  #[error("IO error: {0}")]
15  Io(#[from] io::Error),
16
17  /// JSON parsing error
18  #[error("JSON parsing error: {0}")]
19  Json(#[from] serde_json::Error),
20
21  /// Build failed
22  #[error("Build failed")]
23  BuildFailed,
24
25  /// Process execution error
26  #[error("Process error: {0}")]
27  Process(String),
28
29  /// Configuration error
30  #[error("Configuration error: {0}")]
31  Config(String),
32
33  /// Parse error
34  #[error("Parse error: {0}")]
35  Parse(String),
36
37  /// Terminal error
38  #[error("Terminal error: {0}")]
39  Terminal(String),
40
41  /// Other error
42  #[error("{0}")]
43  Other(String),
44}
45
46impl RomError {
47  /// Create a process error
48  pub fn process<S: Into<String>>(msg: S) -> Self {
49    Self::Process(msg.into())
50  }
51
52  /// Create a config error
53  pub fn config<S: Into<String>>(msg: S) -> Self {
54    Self::Config(msg.into())
55  }
56
57  /// Create a parse error
58  pub fn parse<S: Into<String>>(msg: S) -> Self {
59    Self::Parse(msg.into())
60  }
61
62  /// Create a terminal error
63  pub fn terminal<S: Into<String>>(msg: S) -> Self {
64    Self::Terminal(msg.into())
65  }
66
67  /// Create an other error
68  pub fn other<S: Into<String>>(msg: S) -> Self {
69    Self::Other(msg.into())
70  }
71}