chronon_core/error.rs
1//! Error types for Chronon.
2
3use thiserror::Error;
4
5/// Result type alias for Chronon operations.
6pub type Result<T> = std::result::Result<T, ChrononError>;
7
8/// Errors that can occur in Chronon operations.
9///
10/// Returned by [`SchedulerStore`](crate::store::SchedulerStore) implementations, the runtime
11/// builder, and script dispatch. Hosts typically map these to HTTP status codes or log events.
12#[derive(Debug, Error)]
13pub enum ChrononError {
14 /// No script with the requested name is registered or persisted.
15 #[error("script not found: {0}")]
16 ScriptNotFound(String),
17
18 /// No job with the requested id or name exists in storage.
19 #[error("job not found: {0}")]
20 JobNotFound(String),
21
22 /// No run with the requested id exists in storage.
23 #[error("run not found: {0}")]
24 RunNotFound(String),
25
26 /// Cron expression failed validation (syntax or unsupported field).
27 #[error("invalid cron expression: {0}")]
28 InvalidCron(String),
29
30 /// IANA timezone string could not be parsed.
31 #[error("invalid timezone: {0}")]
32 InvalidTimezone(String),
33
34 /// Job parameters, actor JSON, or handler inputs failed validation or deserialization.
35 #[error("parameter error: {0}")]
36 ParamError(String),
37
38 /// Job references a script name that does not match the registered script identity.
39 #[error("script mismatch for job '{job_name}': expected '{expected}', got '{actual}'")]
40 ScriptMismatch {
41 /// Script name recorded on the job revision.
42 expected: String,
43 /// Script name resolved from the live registry or request.
44 actual: String,
45 /// Human-readable job name for error messages.
46 job_name: String,
47 },
48
49 /// Underlying storage backend failed or returned an unexpected condition.
50 #[error("storage error: {0}")]
51 StorageError(String),
52
53 /// Catch-all for invariant violations, identity reconstruction failures, and bugs.
54 #[error("internal error: {0}")]
55 Internal(String),
56}
57
58impl From<serde_json::Error> for ChrononError {
59 fn from(err: serde_json::Error) -> Self {
60 Self::ParamError(err.to_string())
61 }
62}