Skip to main content

ironflow_runtime/
error.rs

1//! Typed error for the ironflow runtime.
2
3use thiserror::Error;
4use tokio_cron_scheduler::JobSchedulerError;
5
6/// Error returned by [`Runtime::serve`](crate::runtime::Runtime::serve) and
7/// [`Runtime::run_crons`](crate::runtime::Runtime::run_crons).
8#[derive(Debug, Error)]
9pub enum RuntimeError {
10    /// Failed to bind the TCP listener to the requested address.
11    #[error("failed to bind address: {0}")]
12    Bind(std::io::Error),
13    /// A cron expression is invalid or the scheduler failed to start.
14    #[error("cron scheduler error: {0}")]
15    Cron(#[from] JobSchedulerError),
16    /// The Axum server encountered a fatal I/O error.
17    #[error("http server error: {0}")]
18    Serve(std::io::Error),
19    /// The cron scheduler failed to shut down cleanly.
20    #[error("scheduler shutdown error: {0}")]
21    Shutdown(JobSchedulerError),
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn bind_error_display() {
30        let err = RuntimeError::Bind(std::io::Error::new(
31            std::io::ErrorKind::AddrInUse,
32            "port taken",
33        ));
34        assert_eq!(err.to_string(), "failed to bind address: port taken");
35    }
36
37    #[test]
38    fn serve_error_display() {
39        let err = RuntimeError::Serve(std::io::Error::other("fatal"));
40        assert_eq!(err.to_string(), "http server error: fatal");
41    }
42
43    #[test]
44    fn runtime_error_implements_std_error() {
45        let err = RuntimeError::Bind(std::io::Error::other("x"));
46        let _: &dyn std::error::Error = &err;
47    }
48}