martin_core/error.rs
1//! Transport-independent classification of failures.
2//!
3//! Errors here describe *what went wrong* in the vocabulary of the subsystem that failed.
4//! A transport edge needs a different question answered: *whose fault was it, and is a
5//! retry worth trying?* [`ErrorKind`] is that second axis, so an edge maps one small enum
6//! instead of re-matching every subsystem's variants.
7
8/// How a caller should treat a failure, independent of which subsystem produced it.
9///
10/// Deliberately not `#[non_exhaustive]`: adding a kind should break every edge that maps it.
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
12pub enum ErrorKind {
13 /// The requested resource does not exist.
14 NotFound,
15 /// The request was malformed, out of range, or asked for something unsupported.
16 InvalidInput,
17 /// A dependency was reachable but failed to serve the request; a retry may succeed.
18 Unavailable,
19 /// A defect in martin, or a failure that callers cannot act on.
20 Internal,
21}
22
23/// Answers [`ErrorKind`] for an error type.
24///
25/// Prefer widening to [`ErrorKind::Internal`] over guessing: a misclassified
26/// [`ErrorKind::NotFound`] hides a real defect behind a 404.
27pub trait Classify {
28 /// Classifies this failure for a caller that must map it onto a transport.
29 fn kind(&self) -> ErrorKind;
30}