audiorouter_core/
error.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ErrorKind {
9 Config,
11 Runtime,
13}
14
15#[derive(Debug)]
17pub struct AppError {
18 pub kind: ErrorKind,
19 pub message: String,
20}
21
22impl AppError {
23 pub fn config(msg: impl Into<String>) -> Self {
24 Self {
25 kind: ErrorKind::Config,
26 message: msg.into(),
27 }
28 }
29
30 pub fn runtime(msg: impl Into<String>) -> Self {
31 Self {
32 kind: ErrorKind::Runtime,
33 message: msg.into(),
34 }
35 }
36}
37
38impl std::fmt::Display for AppError {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.write_str(&self.message)
41 }
42}
43
44impl std::error::Error for AppError {}
45
46pub fn exit_code_for(kind: ErrorKind) -> i32 {
48 match kind {
49 ErrorKind::Config => 1,
50 ErrorKind::Runtime => 2,
51 }
52}