Skip to main content

lightshuttle_runtime/lifecycle/
error.rs

1//! Error type returned by [`crate::LifecycleManager`] and
2//! [`crate::LifecyclePlan`].
3
4use std::time::Duration;
5
6use lightshuttle_spec::SpecError;
7
8use crate::error::RuntimeError;
9
10/// Errors raised by the lifecycle layer.
11#[derive(Debug, thiserror::Error)]
12pub enum LifecycleError {
13    /// The dependency graph contains a cycle.
14    #[error("cycle detected in dependency graph: {0}")]
15    Cycle(String),
16
17    /// Converting a manifest resource into a [`crate::ContainerSpec`] failed.
18    #[error("manifest conversion failed for `{resource}`")]
19    SpecBuild {
20        /// Resource whose conversion failed.
21        resource: String,
22        /// Underlying specification error.
23        #[source]
24        source: SpecError,
25    },
26
27    /// A resource failed to start.
28    #[error("failed to start resource `{resource}`")]
29    Start {
30        /// Resource that failed.
31        resource: String,
32        /// Underlying runtime error.
33        #[source]
34        source: RuntimeError,
35    },
36
37    /// A resource failed to stop cleanly.
38    #[error("failed to stop resource `{resource}`")]
39    Stop {
40        /// Resource that failed.
41        resource: String,
42        /// Underlying runtime error.
43        #[source]
44        source: RuntimeError,
45    },
46
47    /// A resource never became healthy within the configured timeout.
48    #[error("resource `{resource}` healthcheck timed out after {timeout:?}")]
49    HealthcheckTimeout {
50        /// Resource that did not become healthy.
51        resource: String,
52        /// Configured timeout.
53        timeout: Duration,
54    },
55
56    /// A dependency of the resource failed.
57    #[error("dependency `{dependency}` for `{resource}` failed: {reason}")]
58    DependencyFailed {
59        /// Resource whose start was blocked.
60        resource: String,
61        /// Dependency that failed.
62        dependency: String,
63        /// Reason reported by the failed dependency.
64        reason: String,
65    },
66
67    /// A reference targets a resource that does not exist in the plan.
68    #[error("resource `{0}` not found in the current plan")]
69    ResourceNotFound(String),
70}