rush_sync_server/core/
error.rs

1use 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
18// In src/error.rs
19
20impl std::fmt::Display for AppError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            AppError::Io(err) => write!(
24                f,
25                "{}",
26                get_translation("system.error.io", &[&err.to_string()])
27            ),
28            AppError::Validation(msg) => {
29                write!(f, "{}", get_translation("system.error.validation", &[msg]))
30            }
31            AppError::Terminal(msg) => {
32                write!(f, "{}", get_translation("system.error.terminal", &[msg]))
33            }
34            AppError::Translation(err) => write!(f, "{}", err),
35        }
36    }
37}
38
39impl std::error::Error for AppError {}
40
41pub type Result<T> = std::result::Result<T, AppError>;