Skip to main content

coven_database/
snapshot_error.rs

1//! Snapshot input errors leave the loading transaction unchanged.
2
3/// Snapshots or their gap writes could not be loaded into this database.
4#[derive(Debug, thiserror::Error)]
5pub enum SnapshotError {
6    /// A selected snapshot's plaintext failed while the reload transaction was
7    /// reading it: the loader's format, schema and merge checks, or reading
8    /// the input itself.
9    #[error("reload snapshot {snapshot:?}: {error}")]
10    Body {
11        /// The supplied snapshot's identity.
12        snapshot: coven_format::admin::SnapshotId,
13        /// The failed read or check.
14        #[source]
15        error: Box<crate::DbError>,
16        /// The digest of its staged records as the failed read left them,
17        /// read back once it failed, to tell damage on this device from the
18        /// snapshot's own (§19.1); `None` until then.
19        staged: Option<crate::StagedDigest>,
20    },
21    /// Reading the plaintext supplied by sync failed.
22    #[error("reading reload input: {0}")]
23    Read(#[source] std::io::Error),
24    /// A frame or its merge state failed the format's checks.
25    #[error(transparent)]
26    Format(#[from] coven_format::Error),
27    /// The snapshot needs a different application schema.
28    #[error("snapshot schema {snapshot} cannot load into database schema {database}")]
29    Schema {
30        /// Version declared by the snapshot.
31        snapshot: u32,
32        /// Version prepared on the database connection.
33        database: u32,
34    },
35    /// Authenticating another member's write that the snapshot carries needs
36    /// a key this device has not opened yet (§9.6, D9): loading waits for it.
37    #[error("snapshot write evidence needs key {key} of {audience:?}")]
38    KeyUnavailable {
39        /// The audience whose key seals the evidence.
40        audience: coven_merge::Audience,
41        /// The key the write named.
42        key: coven_foundation::id_source::KeyId,
43    },
44    /// Individually valid records disagree with one another or the schema.
45    #[error("inconsistent snapshot: {0}")]
46    Inconsistent(&'static str),
47    /// Another member's write that the snapshot carries does not
48    /// authenticate: its sealed header does not open with the store key its
49    /// prefix names, or its header signature does not verify (D9).
50    #[error("snapshot write evidence does not authenticate: {0}")]
51    Unauthentic(#[source] coven_crypto::CryptoError),
52    /// Another member's write that the snapshot carries names a device that,
53    /// at the write's read-through, did not belong to a member of every
54    /// audience the write has a part of (D9).
55    #[error("snapshot write evidence names an author who could not write it")]
56    Unauthorized,
57}
58
59pub(crate) fn invalid(reason: &'static str) -> crate::DbError {
60    SnapshotError::Inconsistent(reason).into()
61}