euv_core/runtime/fault/struct.rs
1use super::*;
2
3/// Structured diagnostic snapshot of one panic intercepted by an `ErrorBoundary`.
4#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
5pub struct FaultRecord {
6 /// Monotonic boundary-local fault sequence number.
7 #[get(type(copy))]
8 pub(crate) sequence: u64,
9 /// Execution category where the panic occurred.
10 #[get(type(copy))]
11 pub(crate) origin: FaultOrigin,
12 /// Human-readable scope or widget identifier.
13 pub(crate) scope: String,
14 /// Extracted panic payload message.
15 pub(crate) message: String,
16 /// Caller-supplied monotonic timestamp in milliseconds.
17 #[get(type(copy))]
18 pub(crate) timestamp_ms: u64,
19}
20
21/// Aggregated fault-isolation telemetry snapshot exported by an `ErrorBoundary`.
22#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
23pub struct ErrorBoundaryTelemetry {
24 /// Current health state (`Healthy`, `Degraded`, or `Tripped`).
25 #[get(type(copy))]
26 pub(crate) state: ErrorBoundaryState,
27 /// Cumulative number of caught panics across the boundary lifetime.
28 #[get(type(copy))]
29 pub(crate) total_faults: u64,
30 /// Number of consecutive panics since the last success or recovery.
31 #[get(type(copy))]
32 pub(crate) consecutive_faults: u32,
33 /// Number of explicit recoveries from `Degraded` or `Tripped` back to `Healthy`.
34 #[get(type(copy))]
35 pub(crate) recoveries: u64,
36 /// Cumulative number of guarded invocations that completed without panicking.
37 #[get(type(copy))]
38 pub(crate) successful_invocations: u64,
39 /// Number of recent fault records currently retained in history.
40 #[get(type(copy))]
41 pub(crate) history_len: usize,
42}
43
44/// Panic-isolating fault boundary protecting callbacks, reactive effects, and render hooks.
45#[derive(Clone, Data, Debug)]
46pub struct ErrorBoundary {
47 /// Logical boundary identifier for diagnostics and telemetry attribution.
48 pub(crate) name: String,
49 /// Current boundary health and circuit-breaker state.
50 #[get(type(copy))]
51 pub(crate) state: ErrorBoundaryState,
52 /// Maximum consecutive panics tolerated before transitioning to `Tripped`.
53 #[get(type(copy))]
54 pub(crate) max_consecutive_faults: u32,
55 /// Maximum recent fault records kept in the ring history.
56 #[get(type(copy))]
57 pub(crate) history_limit: usize,
58 /// Total panics intercepted over the lifetime of this boundary.
59 #[get(type(copy))]
60 pub(crate) total_faults: u64,
61 /// Consecutive panics since the last successful call or recovery.
62 #[get(type(copy))]
63 pub(crate) consecutive_faults: u32,
64 /// Number of explicit recoveries performed.
65 #[get(type(copy))]
66 pub(crate) recoveries: u64,
67 /// Total guarded invocations that completed normally.
68 #[get(type(copy))]
69 pub(crate) successful_invocations: u64,
70 /// Next monotonic sequence number assigned to intercepted faults.
71 #[get(pub(crate), type(copy))]
72 #[get_mut(skip)]
73 #[set(pub(crate))]
74 pub(crate) next_sequence: u64,
75 /// Bounded FIFO history of recent intercepted faults.
76 #[get(pub(crate))]
77 #[get_mut(pub(crate))]
78 #[set(skip)]
79 pub(crate) history: VecDeque<FaultRecord>,
80}