serenade_kernel/error.rs
1//! Kernel lifecycle errors.
2
3use crate::KernelPhase;
4
5/// Failure during kernel registration, compile, boot, or shutdown.
6#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
7pub enum KernelError {
8 /// `Environment::from_name` received an empty name.
9 #[error("unknown environment `{0}` (use `dev`, `test`, `prod`, or a non-empty custom name)")]
10 UnknownEnvironment(String),
11 /// An operation was invoked in a phase that does not allow it.
12 #[error("cannot `{action}` while kernel is in phase `{state}`")]
13 InvalidState {
14 /// Attempted operation (`register`, `compile`, `boot`, or `shutdown`).
15 action: &'static str,
16 /// Current lifecycle phase.
17 state: KernelPhase,
18 },
19 /// Two bundles were registered with the same [`BundleInterface::name`](crate::BundleInterface::name).
20 #[error("bundle `{0}` is already registered")]
21 DuplicateBundle(&'static str),
22 /// A bundle listed a dependency that was never registered.
23 #[error("bundle `{bundle}` depends on unknown bundle `{dependency}`")]
24 UnknownBundleDependency {
25 /// Bundle that declared the dependency.
26 bundle: &'static str,
27 /// Missing dependency name.
28 dependency: &'static str,
29 },
30 /// Bundle dependencies form a cycle; `0` is one member of the cycle.
31 #[error("cyclic bundle dependency involving `{0}`")]
32 CyclicBundleDependency(&'static str),
33 /// A bundle returned an error from `build`, `boot`, or `shutdown`.
34 #[error("bundle `{bundle}` failed during {phase}: {message}")]
35 Bundle {
36 /// Bundle name.
37 bundle: &'static str,
38 /// Lifecycle method that failed.
39 phase: &'static str,
40 /// Underlying error text.
41 message: String,
42 },
43}