oxide_k/error.rs
1//! Unified error and result types for the Oxide Kernel.
2
3use thiserror::Error;
4
5/// All errors that can be produced by the kernel and its subsystems.
6#[derive(Debug, Error)]
7pub enum KernelError {
8 /// A module operation failed (load, start, stop, unload, etc.).
9 #[error("module error: {0}")]
10 Module(String),
11
12 /// A message could not be routed on the bus, e.g. because no receiver is
13 /// listening or the channel was closed.
14 #[error("bus error: {0}")]
15 Bus(String),
16
17 /// The state registry returned a database-level error.
18 #[error("registry error: {0}")]
19 Registry(#[from] sqlx::Error),
20
21 /// A configuration key was not found in the registry.
22 #[error("configuration key not found: {0}")]
23 ConfigNotFound(String),
24
25 /// A duplicate module id was registered with the [`ModuleManager`](crate::module::ModuleManager).
26 #[error("module already registered: {0}")]
27 DuplicateModule(String),
28
29 /// A module id was referenced that is not known to the manager.
30 #[error("unknown module: {0}")]
31 UnknownModule(String),
32
33 /// JSON (de)serialization failed.
34 #[error("serialization error: {0}")]
35 Serde(#[from] serde_json::Error),
36
37 /// A publish was rejected because the publisher lacks the required capability.
38 #[error("access denied: `{publisher}` lacks capability `{capability}`")]
39 Denied {
40 /// The publisher that attempted the operation.
41 publisher: String,
42 /// The capability required.
43 capability: String,
44 },
45
46 /// An unexpected, unclassified error.
47 #[error(transparent)]
48 Other(#[from] anyhow::Error),
49}
50
51/// Convenient `Result` alias used throughout the kernel.
52pub type Result<T> = std::result::Result<T, KernelError>;