|
1 |
| -use crate::certificate_creator::CertificateCreationError; |
2 |
| -use crate::snapshot_stores::SnapshotStoreError; |
3 |
| -use crate::{ProtocolError, SignerRegistrationError, SnapshotError}; |
4 |
| - |
5 |
| -use mithril_common::certificate_chain::CertificateVerifierError; |
6 |
| -use mithril_common::chain_observer::ChainObserverError; |
7 |
| -use mithril_common::digesters::{ImmutableDigesterError, ImmutableFileListingError}; |
8 |
| -use mithril_common::entities::BeaconComparisonError; |
9 |
| -use mithril_common::entities::Epoch; |
10 |
| -use mithril_common::store::StoreError; |
11 |
| -use mithril_common::BeaconProviderError; |
12 | 1 | use std::error::Error as StdError;
|
13 |
| -use std::io; |
14 | 2 | use thiserror::Error;
|
15 | 3 |
|
| 4 | +/// Error encountered or produced by the Runtime. |
| 5 | +/// This enum represents the faith of the errors produced during the state |
| 6 | +/// transitions. |
16 | 7 | #[derive(Error, Debug)]
|
17 | 8 | pub enum RuntimeError {
|
18 |
| - #[error("multi signer error: {0}")] |
19 |
| - MultiSigner(#[from] ProtocolError), |
20 |
| - |
21 |
| - #[error("snapshotter error: {0}")] |
22 |
| - Snapshotter(#[from] SnapshotError), |
23 |
| - |
24 |
| - #[error("digester error: {0}")] |
25 |
| - Digester(#[from] ImmutableDigesterError), |
26 |
| - |
27 |
| - #[error("store error: {0}")] |
28 |
| - StoreError(#[from] StoreError), |
29 |
| - |
30 |
| - #[error("snapshot uploader error: {0}")] |
31 |
| - SnapshotUploader(String), |
32 |
| - |
33 |
| - #[error("snapshot build error: {0}")] |
34 |
| - SnapshotBuild(#[from] io::Error), |
35 |
| - |
36 |
| - #[error("immutable file scanning error: {0}")] |
37 |
| - ImmutableFile(#[from] ImmutableFileListingError), |
38 |
| - |
39 |
| - #[error("chain observer error: {0}")] |
40 |
| - ChainObserver(#[from] ChainObserverError), |
41 |
| - |
42 |
| - #[error("beacon provider error: {0}")] |
43 |
| - BeaconProvider(#[from] BeaconProviderError), |
44 |
| - |
45 |
| - #[error("certificate verifier error: {0}")] |
46 |
| - CertificateVerifier(#[from] CertificateVerifierError), |
47 |
| - |
48 |
| - #[error("certificate chain gap error: {0} vs {1}")] |
49 |
| - CertificateChainEpochGap(Epoch, Epoch), |
50 |
| - |
51 |
| - #[error("snapshot store error: {0}")] |
52 |
| - SnapshotStore(#[from] SnapshotStoreError), |
53 |
| - |
54 |
| - #[error("certificate creation error: {0}")] |
55 |
| - CertificateCreation(#[from] CertificateCreationError), |
| 9 | + /// Errors that need the runtime to try again without changing its state. |
| 10 | + #[error("An error occured: {message}. This runtime cycle will be skipped. Nested error: {nested_error:#?}.")] |
| 11 | + KeepState { |
| 12 | + /// error message |
| 13 | + message: String, |
| 14 | + |
| 15 | + /// Eventual caught error |
| 16 | + nested_error: Option<Box<dyn StdError + Sync + Send>>, |
| 17 | + }, |
| 18 | + /// A Critical error means the Runtime stops and the software exits with an |
| 19 | + /// error code. |
| 20 | + #[error("Critical error:'{message}'. Nested error: {nested_error:#?}.")] |
| 21 | + Critical { |
| 22 | + /// error message |
| 23 | + message: String, |
| 24 | + |
| 25 | + /// Eventual caught error |
| 26 | + nested_error: Option<Box<dyn StdError + Sync + Send>>, |
| 27 | + }, |
| 28 | +} |
56 | 29 |
|
57 |
| - #[error("beacon comparison error: {0}")] |
58 |
| - BeaconComparisonError(#[from] BeaconComparisonError), |
| 30 | +impl RuntimeError { |
| 31 | + /// Create a new KeepState error |
| 32 | + pub fn keep_state(message: &str, error: Option<Box<dyn StdError + Sync + Send>>) -> Self { |
| 33 | + Self::KeepState { |
| 34 | + message: message.to_string(), |
| 35 | + nested_error: error, |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + /// Create a new Critical error |
| 40 | + pub fn critical(message: &str, error: Option<Box<dyn StdError + Sync + Send>>) -> Self { |
| 41 | + Self::Critical { |
| 42 | + message: message.to_string(), |
| 43 | + nested_error: error, |
| 44 | + } |
| 45 | + } |
| 46 | +} |
59 | 47 |
|
60 |
| - #[error("signer registration error: {0}")] |
61 |
| - SignerRegistration(#[from] SignerRegistrationError), |
| 48 | +impl From<Box<dyn StdError + Sync + Send>> for RuntimeError { |
| 49 | + fn from(value: Box<dyn StdError + Sync + Send>) -> Self { |
| 50 | + Self::KeepState { |
| 51 | + message: "Error caught, state preserved, will retry to cycle.".to_string(), |
| 52 | + nested_error: Some(value), |
| 53 | + } |
| 54 | + } |
| 55 | +} |
62 | 56 |
|
63 |
| - #[error("general error: {0}")] |
64 |
| - General(Box<dyn StdError + Sync + Send>), |
| 57 | +/// Errors returned when the runner cannot fulfil its missions with no subsystem |
| 58 | +/// to fail. |
| 59 | +#[derive(Debug, Error)] |
| 60 | +pub enum RunnerError { |
| 61 | + /// Protocol message part is missing |
| 62 | + #[error("Missing protocol message: '{0}'.")] |
| 63 | + MissingProtocolMessage(String), |
| 64 | + |
| 65 | + /// Epoch out of bounds |
| 66 | + #[error("Epoch out of bounds: '{0}'.")] |
| 67 | + EpochOutOfBounds(String), |
| 68 | + |
| 69 | + /// No stack distribution found |
| 70 | + #[error("Missing stack distribution: '{0}'.")] |
| 71 | + MissingStakeDistribution(String), |
| 72 | + |
| 73 | + /// Missing protocol parameters |
| 74 | + #[error("Missing protocol parameters: '{0}'.")] |
| 75 | + MissingProtocolParameters(String), |
| 76 | + |
| 77 | + /// No AVK issued by the multisigner |
| 78 | + #[error("No MultiSignature issued: '{0}'.")] |
| 79 | + NoComputedMultiSignature(String), |
65 | 80 | }
|
0 commit comments