Skip to main content

adler_server/
error.rs

1//! Crate-level error type.
2
3use std::io;
4
5use thiserror::Error;
6
7/// Errors surfaced by the public [`serve`](crate::serve) entry point.
8///
9/// All variants carry enough context (a path, the bind address, the
10/// underlying I/O error) to be actionable on their own — no need to
11/// chain back through the call site to figure out what went wrong.
12#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum Error {
15    /// Binding the TCP listener failed (port already in use, permission
16    /// denied, …). The original I/O error is kept for diagnostics.
17    #[error("failed to bind {addr}: {source}")]
18    Bind {
19        /// Address we tried to bind.
20        addr: String,
21        /// Underlying I/O error.
22        #[source]
23        source: io::Error,
24    },
25
26    /// Loading the embedded site registry on startup failed. Practically
27    /// unreachable since the JSON is shipped in the binary, but surfaced
28    /// rather than swallowed so a corrupted custom override is visible.
29    #[error("failed to load site registry: {0}")]
30    Registry(#[from] adler_core::Error),
31
32    /// The axum server task returned an error (typically because the
33    /// listener was closed or accept failed).
34    #[error("HTTP server error: {0}")]
35    Server(#[source] io::Error),
36
37    /// Reading or writing a persisted scan failed.
38    #[error("persistence I/O error: {0}")]
39    Persist(#[source] io::Error),
40
41    /// Serialising a scan to JSON failed (should be unreachable —
42    /// `CheckOutcome` is well-defined serde data).
43    #[error("persistence encode error: {0}")]
44    PersistEncode(#[source] serde_json::Error),
45}
46
47/// `Result<T, Error>` alias used throughout the crate.
48pub type Result<T> = std::result::Result<T, Error>;