Skip to main content

ryg_rans_rs_cli/
exit.rs

1//! # Stable exit codes for the ryg-rans CLI
2//!
3//! All exit codes are stable once documented.  Changing an exit code is a
4//! breaking change for automation consumers.
5
6/// Exit code constants.
7///
8/// | Code | Meaning |
9/// |------|---------|
10/// | 0 | Success |
11/// | 2 | Command-line usage error (Clap) |
12/// | 3 | Input/output error |
13/// | 4 | Container or model format error |
14/// | 5 | Integrity verification failure |
15/// | 6 | Unsupported codec or format version |
16/// | 7 | Resource limit exceeded |
17/// | 8 | Parity or comparison mismatch |
18/// | 9 | Requested backend unavailable |
19/// | 10 | Internal invariant failure |
20pub mod codes {
21    /// Success.
22    pub const SUCCESS: i32 = 0;
23    /// Command-line usage error (handled by Clap).
24    pub const USAGE: i32 = 2;
25    /// Input/output error.
26    pub const IO_ERROR: i32 = 3;
27    /// Container or model format error.
28    pub const FORMAT_ERROR: i32 = 4;
29    /// Integrity verification failure.
30    pub const INTEGRITY_ERROR: i32 = 5;
31    /// Unsupported codec or format version.
32    pub const UNSUPPORTED: i32 = 6;
33    /// Resource limit exceeded.
34    pub const RESOURCE_LIMIT: i32 = 7;
35    /// Parity or comparison mismatch.
36    pub const COMPARISON_MISMATCH: i32 = 8;
37    /// Requested backend unavailable.
38    pub const BACKEND_UNAVAILABLE: i32 = 9;
39    /// Internal invariant failure.
40    pub const INTERNAL_ERROR: i32 = 10;
41}
42
43/// Convert an error reference to a stable exit code.
44pub fn error_to_exit_code(error: &crate::error::AppError) -> i32 {
45    match error {
46        crate::error::AppError::Io(_) => codes::IO_ERROR,
47        crate::error::AppError::Format(_) => codes::FORMAT_ERROR,
48        crate::error::AppError::Model(_) => codes::FORMAT_ERROR,
49        crate::error::AppError::Codec(_) => codes::FORMAT_ERROR,
50        crate::error::AppError::Integrity(_) => codes::INTEGRITY_ERROR,
51        crate::error::AppError::ResourceLimit(_) => codes::RESOURCE_LIMIT,
52        crate::error::AppError::Backend(_) => codes::BACKEND_UNAVAILABLE,
53        crate::error::AppError::Comparison(_) => codes::COMPARISON_MISMATCH,
54        crate::error::AppError::ExternalOracle(_) => codes::IO_ERROR,
55        crate::error::AppError::InternalInvariant(_) => codes::INTERNAL_ERROR,
56    }
57}