switchyard/api/errors/
map.rs

1use std::io::ErrorKind;
2
3use super::ErrorId;
4
5/// Map errors from atomic swap/symlink replacement to stable `ErrorId`.
6#[must_use]
7pub fn map_swap_error(e: &std::io::Error) -> ErrorId {
8    let emsg = e.to_string();
9    if emsg.contains("sidecar write failed") {
10        return ErrorId::E_POLICY;
11    }
12    match e.raw_os_error() {
13        Some(code) if code == libc::EXDEV => ErrorId::E_EXDEV,
14        _ => ErrorId::E_ATOMIC_SWAP,
15    }
16}
17
18/// Map restore error kinds to stable `ErrorId` for telemetry.
19///
20/// Keep this conservative to support older stable compilers; many `ErrorKind`
21/// variants (e.g., `NotADirectory`, `IsADirectory`) were stabilized later.
22#[must_use]
23pub const fn map_restore_error_kind(kind: ErrorKind) -> ErrorId {
24    match kind {
25        ErrorKind::NotFound => ErrorId::E_BACKUP_MISSING,
26        _ => ErrorId::E_RESTORE_FAILED,
27    }
28}