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