Skip to main content

forge_core/
error.rs

1use std::time::Duration;
2
3use thiserror::Error;
4
5/// Core error type for FORGE operations.
6#[derive(Error, Debug)]
7pub enum ForgeError {
8    #[error("Configuration error: {0}")]
9    Config(String),
10
11    #[error("Database error: {0}")]
12    Database(String),
13
14    #[error("Function error: {0}")]
15    Function(String),
16
17    #[error("Job error: {0}")]
18    Job(String),
19
20    #[error("Cluster error: {0}")]
21    Cluster(String),
22
23    #[error("Serialization error: {0}")]
24    Serialization(String),
25
26    #[error("Deserialization error: {0}")]
27    Deserialization(String),
28
29    #[error("IO error: {0}")]
30    Io(#[from] std::io::Error),
31
32    #[error("SQL error: {0}")]
33    Sql(#[from] sqlx::Error),
34
35    #[error("Invalid argument: {0}")]
36    InvalidArgument(String),
37
38    #[error("Not found: {0}")]
39    NotFound(String),
40
41    #[error("Unauthorized: {0}")]
42    Unauthorized(String),
43
44    #[error("Forbidden: {0}")]
45    Forbidden(String),
46
47    #[error("Validation error: {0}")]
48    Validation(String),
49
50    #[error("Timeout: {0}")]
51    Timeout(String),
52
53    #[error("Internal error: {0}")]
54    Internal(String),
55
56    #[error("Invalid state: {0}")]
57    InvalidState(String),
58
59    #[error("Workflow suspended")]
60    WorkflowSuspended,
61
62    #[error("Rate limit exceeded: retry after {retry_after:?}")]
63    RateLimitExceeded {
64        retry_after: Duration,
65        limit: u32,
66        remaining: u32,
67    },
68}
69
70impl From<serde_json::Error> for ForgeError {
71    fn from(e: serde_json::Error) -> Self {
72        ForgeError::Serialization(e.to_string())
73    }
74}
75
76/// Result type alias using ForgeError.
77pub type Result<T> = std::result::Result<T, ForgeError>;