|
1 |
| -use crate::certificate_creator::CertificateCreationError; |
2 |
| -use crate::snapshot_stores::SnapshotStoreError; |
3 |
| -use crate::{ProtocolError, SignerRegistrationError, SnapshotError}; |
| 1 | +use crate::ProtocolError; |
4 | 2 |
|
5 | 3 | use mithril_common::certificate_chain::CertificateVerifierError;
|
6 | 4 | use mithril_common::chain_observer::ChainObserverError;
|
7 |
| -use mithril_common::digesters::{ImmutableDigesterError, ImmutableFileListingError}; |
| 5 | +use mithril_common::digesters::ImmutableDigesterError; |
8 | 6 | use mithril_common::entities::BeaconComparisonError;
|
9 |
| -use mithril_common::entities::Epoch; |
10 | 7 | use mithril_common::store::StoreError;
|
11 | 8 | use mithril_common::BeaconProviderError;
|
12 | 9 | use std::error::Error as StdError;
|
13 |
| -use std::io; |
14 | 10 | use thiserror::Error;
|
15 | 11 |
|
| 12 | +/// Error encountered or produced by the Runtime. |
| 13 | +/// This enum represents the faith of the errors produced during the state |
| 14 | +/// transitions. |
16 | 15 | #[derive(Error, Debug)]
|
17 | 16 | pub enum RuntimeError {
|
18 |
| - /// MultiSigner error |
19 |
| - #[error("multi signer error: {0}")] |
20 |
| - MultiSigner(#[from] ProtocolError), |
21 |
| - |
22 |
| - #[error("snapshotter error: {0}")] |
23 |
| - Snapshotter(#[from] SnapshotError), |
24 |
| - |
25 |
| - #[error("digester error: {0}")] |
26 |
| - Digester(#[from] ImmutableDigesterError), |
27 |
| - |
28 |
| - #[error("store error: {0}")] |
29 |
| - StoreError(#[from] StoreError), |
30 |
| - |
31 |
| - #[error("snapshot uploader error: {0}")] |
32 |
| - SnapshotUploader(String), |
33 |
| - |
34 |
| - #[error("snapshot build error: {0}")] |
35 |
| - SnapshotBuild(#[from] io::Error), |
36 |
| - |
37 |
| - #[error("immutable file scanning error: {0}")] |
38 |
| - ImmutableFile(#[from] ImmutableFileListingError), |
| 17 | + /// Errors that need the runtime to try again without changing its state. |
| 18 | + #[error("An error occured: {message}. This runtime cycle will be skipped. Nested error: {nested_error:#?}.")] |
| 19 | + KeepState { |
| 20 | + /// error message |
| 21 | + message: String, |
39 | 22 |
|
40 |
| - #[error("chain observer error: {0}")] |
41 |
| - ChainObserver(#[from] ChainObserverError), |
| 23 | + /// Eventual caught error |
| 24 | + nested_error: Option<Box<dyn StdError + Sync + Send>>, |
| 25 | + }, |
| 26 | + /// A Critical error means the Runtime stops and the software exits with an |
| 27 | + /// error code. |
| 28 | + #[error("Critical error:'{message}'. Nested error: {nested_error:#?}.")] |
| 29 | + Critical { |
| 30 | + /// error message |
| 31 | + message: String, |
42 | 32 |
|
43 |
| - #[error("beacon provider error: {0}")] |
44 |
| - BeaconProvider(#[from] BeaconProviderError), |
| 33 | + /// Eventual caught error |
| 34 | + nested_error: Option<Box<dyn StdError + Sync + Send>>, |
| 35 | + }, |
| 36 | +} |
45 | 37 |
|
46 |
| - #[error("certificate verifier error: {0}")] |
47 |
| - CertificateVerifier(#[from] CertificateVerifierError), |
| 38 | +impl RuntimeError { |
| 39 | + /// Create a new KeepState error |
| 40 | + pub fn keep_state(message: &str, error: Option<Box<dyn StdError + Sync + Send>>) -> Self { |
| 41 | + Self::KeepState { |
| 42 | + message: message.to_string(), |
| 43 | + nested_error: error, |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /// Create a new Critical error |
| 48 | + pub fn critical(message: &str, error: Option<Box<dyn StdError + Sync + Send>>) -> Self { |
| 49 | + Self::Critical { |
| 50 | + message: message.to_string(), |
| 51 | + nested_error: error, |
| 52 | + } |
| 53 | + } |
| 54 | +} |
48 | 55 |
|
49 |
| - #[error("certificate chain gap error: {0} vs {1}")] |
50 |
| - CertificateChainEpochGap(Epoch, Epoch), |
| 56 | +impl From<BeaconComparisonError> for RuntimeError { |
| 57 | + fn from(value: BeaconComparisonError) -> Self { |
| 58 | + Self::KeepState { |
| 59 | + message: "Beacon comparison error".to_string(), |
| 60 | + nested_error: Some(value.into()), |
| 61 | + } |
| 62 | + } |
| 63 | +} |
51 | 64 |
|
52 |
| - #[error("snapshot store error: {0}")] |
53 |
| - SnapshotStore(#[from] SnapshotStoreError), |
| 65 | +impl From<ImmutableDigesterError> for RuntimeError { |
| 66 | + fn from(value: ImmutableDigesterError) -> Self { |
| 67 | + Self::KeepState { |
| 68 | + message: "Error while reading immutable files".to_string(), |
| 69 | + nested_error: Some(value.into()), |
| 70 | + } |
| 71 | + } |
| 72 | +} |
54 | 73 |
|
55 |
| - #[error("certificate creation error: {0}")] |
56 |
| - CertificateCreation(#[from] CertificateCreationError), |
| 74 | +impl From<ProtocolError> for RuntimeError { |
| 75 | + fn from(value: ProtocolError) -> Self { |
| 76 | + Self::KeepState { |
| 77 | + message: "Mithril Protocol Error".to_string(), |
| 78 | + nested_error: Some(value.into()), |
| 79 | + } |
| 80 | + } |
| 81 | +} |
57 | 82 |
|
58 |
| - #[error("beacon comparison error: {0}")] |
59 |
| - BeaconComparisonError(#[from] BeaconComparisonError), |
| 83 | +impl From<ChainObserverError> for RuntimeError { |
| 84 | + fn from(value: ChainObserverError) -> Self { |
| 85 | + Self::KeepState { |
| 86 | + message: "Chain observer error".to_string(), |
| 87 | + nested_error: Some(value.into()), |
| 88 | + } |
| 89 | + } |
| 90 | +} |
60 | 91 |
|
61 |
| - #[error("signer registration error: {0}")] |
62 |
| - SignerRegistration(#[from] SignerRegistrationError), |
| 92 | +impl From<StoreError> for RuntimeError { |
| 93 | + fn from(value: StoreError) -> Self { |
| 94 | + Self::KeepState { |
| 95 | + message: "Store Error".to_string(), |
| 96 | + nested_error: Some(value.into()), |
| 97 | + } |
| 98 | + } |
| 99 | +} |
63 | 100 |
|
64 |
| - #[error("general error: {0}")] |
65 |
| - General(Box<dyn StdError + Sync + Send>), |
| 101 | +impl From<BeaconProviderError> for RuntimeError { |
| 102 | + fn from(value: BeaconProviderError) -> Self { |
| 103 | + Self::KeepState { |
| 104 | + message: "Could not read beacon from chain".to_string(), |
| 105 | + nested_error: Some(value.into()), |
| 106 | + } |
| 107 | + } |
| 108 | +} |
66 | 109 |
|
67 |
| - /// A Critical error means the Runtime stops and the software exits with an |
68 |
| - /// error code. |
69 |
| - #[error("Critical error '{message}'. Nested error: {nested_error:#?}")] |
70 |
| - Critical { |
71 |
| - message: String, |
72 |
| - nested_error: Option<Box<dyn StdError + Sync + Send>>, |
73 |
| - }, |
| 110 | +impl From<CertificateVerifierError> for RuntimeError { |
| 111 | + fn from(value: CertificateVerifierError) -> Self { |
| 112 | + Self::KeepState { |
| 113 | + message: "Could not verify given certificate".to_string(), |
| 114 | + nested_error: Some(value.into()), |
| 115 | + } |
| 116 | + } |
74 | 117 | }
|
0 commit comments