Skip to main content

atomcode_core/setup/
error.rs

1//! Public error type. thiserror because atomcode-core is library code.
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum SetupError {
7    // ── Lock ──
8    #[error("Setup is already running (PID {pid} @ {host}, started {start_time}). Use --force to override.")]
9    LockHeld {
10        pid: u32,
11        start_time: String,
12        host: String,
13    },
14
15    #[error("Setup lock io error: {0}")]
16    LockIo(#[source] std::io::Error),
17
18    // ── Catch-all wrapper ──
19    #[error("Unexpected io error: {0}")]
20    Io(#[from] std::io::Error),
21
22    #[error("Unexpected error: {0}")]
23    Other(#[from] anyhow::Error),
24}
25
26pub type SetupResult<T> = Result<T, SetupError>;
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn display_lock_held_includes_pid_and_host() {
34        let e = SetupError::LockHeld {
35            pid: 1234,
36            start_time: "2026-05-19T10:00:00Z".into(),
37            host: "macbook".into(),
38        };
39        let s = format!("{e}");
40        assert!(s.contains("1234"));
41        assert!(s.contains("macbook"));
42        assert!(s.contains("--force"));
43    }
44
45}