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("Job cancelled: {0}")]
21    JobCancelled(String),
22
23    #[error("Cluster error: {0}")]
24    Cluster(String),
25
26    #[error("Serialization error: {0}")]
27    Serialization(String),
28
29    #[error("Deserialization error: {0}")]
30    Deserialization(String),
31
32    #[error("IO error: {0}")]
33    Io(#[from] std::io::Error),
34
35    #[error("SQL error: {0}")]
36    Sql(#[from] sqlx::Error),
37
38    #[error("Invalid argument: {0}")]
39    InvalidArgument(String),
40
41    #[error("Not found: {0}")]
42    NotFound(String),
43
44    #[error("Unauthorized: {0}")]
45    Unauthorized(String),
46
47    #[error("Forbidden: {0}")]
48    Forbidden(String),
49
50    #[error("Validation error: {0}")]
51    Validation(String),
52
53    #[error("Timeout: {0}")]
54    Timeout(String),
55
56    #[error("Internal error: {0}")]
57    Internal(String),
58
59    #[error("Invalid state: {0}")]
60    InvalidState(String),
61
62    #[error("Workflow suspended")]
63    WorkflowSuspended,
64
65    #[error("Rate limit exceeded: retry after {retry_after:?}")]
66    RateLimitExceeded {
67        retry_after: Duration,
68        limit: u32,
69        remaining: u32,
70    },
71}
72
73impl From<serde_json::Error> for ForgeError {
74    fn from(e: serde_json::Error) -> Self {
75        ForgeError::Serialization(e.to_string())
76    }
77}
78
79/// Result type alias using ForgeError.
80pub type Result<T> = std::result::Result<T, ForgeError>;