rush_sync_server/core/
error.rs1use crate::core::prelude::*;
2use std::io;
3
4#[derive(Debug)]
5pub enum AppError {
6 Io(io::Error),
7 Validation(String),
8 Terminal(String),
9 Translation(TranslationError),
10}
11
12impl From<io::Error> for AppError {
13 fn from(err: io::Error) -> Self {
14 AppError::Terminal(err.to_string())
15 }
16}
17
18impl std::fmt::Display for AppError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 AppError::Io(err) => write!(
22 f,
23 "{}",
24 get_translation("system.error.io_error", &[&err.to_string()])
25 ),
26 AppError::Validation(msg) => write!(
27 f,
28 "{}",
29 get_translation("system.error.validation_error", &[msg])
30 ),
31 AppError::Terminal(msg) => write!(
32 f,
33 "{}",
34 get_translation("system.error.terminal_error", &[msg])
35 ),
36 AppError::Translation(err) => write!(
37 f,
38 "{}",
39 get_translation("system.error.translation_error", &[&err.to_string()])
40 ),
41 }
42 }
43}
44
45impl std::error::Error for AppError {}
46pub type Result<T> = std::result::Result<T, AppError>;