keystate_core/error.rs
1//! Error and result types shared across the crate and its ports.
2
3/// The error type used by every port in `keystate-core`.
4///
5/// Adapters and sinks wrap their own failures with [`Error::Other`] (for
6/// typed errors) or [`Error::Message`] (for simple strings). Successful
7/// composition never requires core to know a backend's error types.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 /// A JSON (de)serialization failure.
11 #[error("JSON (de)serialization failed: {0}")]
12 Json(#[from] serde_json::Error),
13
14 /// A backend/schema version string could not be parsed.
15 #[error("invalid version string {input:?}: {reason}")]
16 InvalidVersion {
17 /// The string that failed to parse.
18 input: String,
19 /// Why parsing failed.
20 reason: String,
21 },
22
23 /// A [`FieldManifest`](crate::FieldManifest) failed its consistency
24 /// checks and cannot be trusted for verification.
25 #[error("invalid manifest: {0}")]
26 InvalidManifest(String),
27
28 /// A plain-message error, for cases that do not warrant a typed variant.
29 #[error("{0}")]
30 Message(String),
31
32 /// Any other failure coming from an adapter or sink implementation.
33 #[error(transparent)]
34 Other(#[from] Box<dyn std::error::Error + Send + Sync>),
35}
36
37/// Convenience alias used across `keystate-core` and implemented by adapters.
38pub type Result<T> = std::result::Result<T, Error>;