Skip to main content

boson_core/
error.rs

1//! Error types for Boson core operations.
2
3use thiserror::Error;
4
5/// Result type alias for Boson core operations.
6pub type Result<T> = std::result::Result<T, BosonError>;
7
8/// Errors that can occur in Boson operations.
9#[derive(Debug, Error)]
10pub enum BosonError {
11    /// Task not found in registry.
12    #[error("task not found: {0}")]
13    TaskNotFound(String),
14
15    /// Job not found.
16    #[error("job not found: {0}")]
17    JobNotFound(String),
18
19    /// Run not found.
20    #[error("run not found: {0}")]
21    RunNotFound(String),
22
23    /// Task config not found.
24    #[error("task config not found: {0}")]
25    TaskConfigNotFound(String),
26
27    /// Parameter serialization/deserialization error.
28    #[error("parameter error: {0}")]
29    ParamError(String),
30
31    /// Signature mismatch between job and current task.
32    #[error("signature mismatch: job expects {expected}, task has {actual}")]
33    SignatureMismatch {
34        /// Expected signature from the enqueued job.
35        expected: String,
36        /// Current task signature in the registry.
37        actual: String,
38    },
39
40    /// Invalid priority or pool.
41    #[error("invalid config: {0}")]
42    InvalidConfig(String),
43
44    /// Persistence / adapter backend failure.
45    #[error("backend error: {0}")]
46    Backend(String),
47
48    /// Internal error.
49    #[error("internal error: {0}")]
50    Internal(String),
51
52    /// Enqueue blocked by rate limit or in-flight cap; caller should retry after backoff.
53    #[error("enqueue rate limited for task: {0}")]
54    RateLimited(String),
55
56    /// Named queue backend not registered on the router.
57    #[error("unknown queue backend: {0}")]
58    UnknownBackend(String),
59}
60
61/// Identity reconstruction failure at handler boundary.
62#[derive(Debug, Error)]
63pub enum IdentityError {
64    /// Actor JSON could not be parsed or mapped.
65    #[error("invalid actor: {0}")]
66    InvalidActor(String),
67}
68
69impl From<serde_json::Error> for BosonError {
70    fn from(err: serde_json::Error) -> Self {
71        Self::ParamError(err.to_string())
72    }
73}