tx2_core/
error.rs

1use thiserror::Error;
2use crate::system::SystemId;
3
4#[derive(Error, Debug)]
5pub enum TX2Error {
6    #[error("{message}")]
7    Generic {
8        message: String,
9        code: String,
10    },
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum SystemErrorStrategy {
15    Disable,
16    Ignore,
17    Retry,
18}
19
20pub struct SystemErrorContext {
21    pub system_id: SystemId,
22    pub error: String, // Rust errors are traits, simplified to String for context
23    pub phase: String,
24    pub consecutive_failures: u32,
25}
26
27pub type SystemErrorHandler = fn(&SystemErrorContext) -> SystemErrorStrategy;
28
29pub fn default_error_handler(ctx: &SystemErrorContext) -> SystemErrorStrategy {
30    eprintln!(
31        "System {} failed in phase {}: {} (failures: {})",
32        ctx.system_id, ctx.phase, ctx.error, ctx.consecutive_failures
33    );
34
35    if ctx.consecutive_failures >= 3 {
36        eprintln!("System {} disabled due to excessive failures", ctx.system_id);
37        return SystemErrorStrategy::Disable;
38    }
39
40    SystemErrorStrategy::Ignore
41}