fraiseql_error/observer.rs
1/// Errors that occur in the observer / event-processing subsystem.
2///
3/// Observers watch for database change events and execute configured actions
4/// (webhooks, notifications, cache invalidations, etc.).
5#[derive(Debug, thiserror::Error)]
6pub enum ObserverError {
7 /// The observer's trigger condition expression could not be parsed or
8 /// evaluated.
9 #[error("Invalid condition: {message}")]
10 InvalidCondition {
11 /// Description of why the condition is invalid.
12 message: String,
13 },
14
15 /// An error occurred while rendering an observer action template (e.g.
16 /// an email body or webhook payload template).
17 #[error("Template error: {message}")]
18 TemplateError {
19 /// Description of the template rendering failure.
20 message: String,
21 },
22
23 /// The configured action (e.g. HTTP call, notification dispatch) failed
24 /// to execute.
25 #[error("Action failed: {action} - {message}")]
26 ActionFailed {
27 /// Name or type of the action that failed.
28 action: String,
29 /// Reason for the failure.
30 message: String,
31 },
32
33 /// The observer definition contains an invalid or inconsistent
34 /// configuration value.
35 #[error("Invalid configuration: {message}")]
36 InvalidConfig {
37 /// Description of the configuration problem.
38 message: String,
39 },
40
41 /// The event payload could not be processed (e.g. deserialization failed
42 /// or required fields were missing).
43 #[error("Event processing failed: {message}")]
44 ProcessingFailed {
45 /// Description of the processing failure.
46 message: String,
47 },
48
49 /// The event has been retried the maximum number of times without
50 /// succeeding and is being moved to the dead-letter queue.
51 #[error("Max retries exceeded for event {event_id}")]
52 MaxRetriesExceeded {
53 /// Identifier of the event that exhausted its retry budget.
54 event_id: String,
55 },
56
57 /// A database error occurred while recording observer state or audit logs.
58 #[error("Database error: {0}")]
59 Database(#[from] sqlx::Error),
60}
61
62impl ObserverError {
63 /// Returns a short, stable error code string suitable for API responses and
64 /// structured logging.
65 pub const fn error_code(&self) -> &'static str {
66 match self {
67 Self::InvalidCondition { .. } => "observer_invalid_condition",
68 Self::TemplateError { .. } => "observer_template_error",
69 Self::ActionFailed { .. } => "observer_action_failed",
70 Self::InvalidConfig { .. } => "observer_invalid_config",
71 Self::ProcessingFailed { .. } => "observer_processing_failed",
72 Self::MaxRetriesExceeded { .. } => "observer_max_retries",
73 Self::Database(_) => "observer_database_error",
74 }
75 }
76}