#[derive(Debug, thiserror::Error)]
pub enum LedgerError {
#[error("workstream not found: {0}")]
NotFound(String),
#[error("attempted to mutate immutable field `{0}` after creation")]
ImmutableField(&'static str),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
#[error("unsupported: {0}")]
NotSupported(String),
}
#[cfg(test)]
mod tests {
use super::LedgerError;
#[test]
fn display_messages_are_stable() {
assert_eq!(
LedgerError::NotFound("ws-1".into()).to_string(),
"workstream not found: ws-1"
);
assert_eq!(
LedgerError::ImmutableField("assigned_harness").to_string(),
"attempted to mutate immutable field `assigned_harness` after creation"
);
assert_eq!(
LedgerError::NotSupported("not wired yet".into()).to_string(),
"unsupported: not wired yet"
);
let io_err: LedgerError = std::io::Error::new(std::io::ErrorKind::NotFound, "gone").into();
assert!(io_err.to_string().starts_with("io error:"));
let json_err: LedgerError = serde_json::from_str::<serde_json::Value>("{bad")
.unwrap_err()
.into();
assert!(json_err.to_string().starts_with("json error:"));
}
}