Skip to main content

bb_runtime/errors/
restore.rs

1//! `RestoreError`
2//!
3//! Returned by `Node::restore(snapshot)` when the snapshot can't be
4//! reconciled with the current Node's installed modules + wire types.
5//! Distinct from [`crate::concrete::RestoreError`], which is the
6//! per-component deserialization error type that this enum wraps.
7
8/// Errors surfaced by `Node::restore` (the public surface arrives in
9/// the commit that lands `src/node.rs`).
10#[derive(Debug)]
11pub enum RestoreError {
12    /// Snapshot-level invariant violation (incarnation mismatch,
13    /// component table mismatch, graph not found, etc.).
14    SnapshotMismatch(String),
15
16    /// One of the snapshotted components failed to deserialize via
17    /// its registered `RestoreFn`.
18    ComponentRestoreFailed {
19        /// `ConcreteComponent::TYPE_NAME` of the failing component.
20        type_name: String,
21        /// The per-component error.
22        source: crate::concrete::RestoreError,
23    },
24
25    /// Snapshot's `spec_version` doesn't match the live Node's
26    /// `CURRENT_SNAPSHOT_SPEC_VERSION`. Bumps to the spec version
27    /// happen when the `FrameworkSnapshot` shape changes in a way
28    /// older code cannot soundly restore.
29    SpecVersionMismatch {
30        /// Version stamped on the snapshot.
31        got: u32,
32        /// Version this build supports.
33        expected: u32,
34    },
35}
36
37impl std::fmt::Display for RestoreError {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        match self {
40            Self::SnapshotMismatch(reason) => write!(f, "snapshot mismatch: {reason}"),
41            Self::ComponentRestoreFailed { type_name, source } => {
42                write!(f, "component {type_name} restore failed: {source}",)
43            }
44            Self::SpecVersionMismatch { got, expected } => write!(
45                f,
46                "snapshot spec_version mismatch: got={got}, expected={expected}",
47            ),
48        }
49    }
50}
51
52impl std::error::Error for RestoreError {
53    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54        match self {
55            Self::ComponentRestoreFailed { source, .. } => Some(source),
56            _ => None,
57        }
58    }
59}
60