Skip to main content

zeph_scheduler/
error.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use thiserror::Error;
5
6/// Errors that can occur inside the scheduler subsystem.
7#[derive(Debug, Error)]
8pub enum SchedulerError {
9    /// The provided cron expression could not be parsed.
10    ///
11    /// The inner string contains the original expression and the parser's error message.
12    #[error("invalid cron expression: {0}")]
13    InvalidCron(String),
14
15    /// A low-level `SQLx` error occurred during a database operation.
16    #[error("database error: {0}")]
17    Database(#[from] zeph_db::SqlxError),
18
19    /// A high-level `zeph-db` error occurred (e.g. during migrations or connection setup).
20    #[error("database error: {0}")]
21    Db(#[from] zeph_db::DbError),
22
23    /// The [`crate::TaskHandler`] returned an error during task execution.
24    ///
25    /// The inner string is the human-readable description from the handler.
26    #[error("task execution failed: {0}")]
27    TaskFailed(String),
28
29    /// A job with the given name already exists in the store.
30    ///
31    /// Returned by [`crate::JobStore::insert_job`] on a UNIQUE constraint violation.
32    #[error("job '{0}' already exists")]
33    DuplicateJob(String),
34
35    /// Another `zeph serve` instance is already running with the given PID.
36    ///
37    /// Returned by [`crate::PidFile::acquire`] when the pid file is locked by another process.
38    #[cfg(unix)]
39    #[error(
40        "daemon pid file is locked: another zeph serve instance appears to be running (pid {pid})"
41    )]
42    AlreadyRunning {
43        /// PID of the running daemon, as stored in the pid file.
44        pid: u32,
45    },
46
47    /// Failed to detach the daemon process (fork, exec, or I/O redirection error).
48    #[cfg(unix)]
49    #[error("daemon detach failed: {0}")]
50    Detach(String),
51
52    /// A generic I/O error from daemon lifecycle operations (pid file, log file).
53    #[cfg(unix)]
54    #[error("daemon I/O error: {0}")]
55    Io(String),
56}