engine/snapshot/migration/
error.rs

1// Copyright 2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crypto::keys::age;
5use thiserror::Error as DeriveError;
6
7#[derive(Debug, DeriveError)]
8pub enum Error {
9    /// Can't migrate between selected versions.
10    #[error("can't migrate between selected versions")]
11    BadMigrationVersion,
12    /// Input snapshot has incorrect/unexpected version.
13    #[error("input snapshot has incorrect/unexpected version")]
14    BadSnapshotVersion,
15    /// Input file has incorrect format.
16    #[error("input file has incorrect format")]
17    BadSnapshotFormat,
18    /// Failed to decrypt snapshot: incorrect password or corrupt data.
19    #[error("failed to decrypt snapshot: incorrect password or corrupt data")]
20    DecryptFailed,
21    /// Failed to decompress snapshot.
22    #[error("failed to decompress snapshot")]
23    DecompressFailed,
24    /// Authenticated associated data is not supported by snapshot format.
25    #[error("authenticated associated data is not supported by snapshot format")]
26    AadNotSupported,
27    /// Failed to generate randomness.
28    #[error("failed to generate randomness")]
29    RngFailed,
30    /// Age format error.
31    #[error("age format error")]
32    AgeFormatError(age::DecError),
33    /// I/O error.
34    #[error("I/O error")]
35    IoError(std::io::Error),
36    /// Crypto error.
37    #[error("crypto error")]
38    CryptoError(crypto::Error),
39}
40
41impl From<age::DecError> for Error {
42    fn from(e: age::DecError) -> Self {
43        Self::AgeFormatError(e)
44    }
45}
46
47impl From<std::io::Error> for Error {
48    fn from(e: std::io::Error) -> Self {
49        Self::IoError(e)
50    }
51}
52
53impl From<crypto::Error> for Error {
54    fn from(e: crypto::Error) -> Self {
55        Self::CryptoError(e)
56    }
57}