pan_common/error.rs
1use serde::Serialize;
2
3/// Exit codes for structured error reporting (POSIX-style).
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
5#[serde(into = "u8")]
6pub enum ExitCode {
7 Success = 0,
8 General = 1,
9 InputFile = 2,
10 OutputIssue = 3,
11 Unsupported = 4,
12 BadArgs = 5,
13}
14
15impl From<ExitCode> for u8 {
16 fn from(code: ExitCode) -> u8 {
17 code as u8
18 }
19}
20
21/// Trait for domain-specific errors with structured output support.
22pub trait StructuredError: std::fmt::Display + Serialize {
23 /// Return the exit code for this error.
24 fn exit_code(&self) -> ExitCode;
25
26 /// Return a human-readable suggestion for resolving this error.
27 fn suggestion(&self) -> &str;
28}