Skip to content

Commit fd24f7d

Browse files
committed
style(signer): align state machine logs system with aggregator
1 parent e86fa7e commit fd24f7d

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

mithril-signer/src/runtime/error.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use slog::{crit, error, Logger};
2-
use std::fmt::Display;
2+
use thiserror::Error;
33

44
use mithril_common::entities::EpochError;
55
use mithril_common::StdError;
@@ -8,24 +8,28 @@ use crate::RunnerError;
88

99
/// RuntimeError
1010
/// Error kinds tied to their faith in the state machine.
11-
#[derive(Debug)]
11+
#[derive(Error, Debug)]
1212
pub enum RuntimeError {
1313
/// KeepState error means the runtime will keep its state and try to cycle
1414
/// again.
15+
#[error("An error occurred, runtime state kept. message = '{message}'")]
1516
KeepState {
1617
/// Context error message
1718
message: String,
1819

1920
/// Eventual previous error message
21+
#[source]
2022
nested_error: Option<StdError>,
2123
},
2224
/// Critical error means the runtime will exit and the software will return
2325
/// an error code.
26+
#[error("A critical error occurred, aborting runtime. message = '{message}'")]
2427
Critical {
2528
/// Context error message
2629
message: String,
2730

2831
/// Eventual previous error message
32+
#[source]
2933
nested_error: Option<StdError>,
3034
},
3135
}
@@ -57,27 +61,6 @@ impl RuntimeError {
5761
}
5862
}
5963

60-
impl std::error::Error for RuntimeError {}
61-
62-
impl Display for RuntimeError {
63-
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64-
match self {
65-
Self::KeepState { message, .. } => {
66-
write!(
67-
formatter,
68-
"An error occurred, runtime state kept. message = '{message}'"
69-
)
70-
}
71-
Self::Critical { message, .. } => {
72-
write!(
73-
formatter,
74-
"A critical error occurred, aborting runtime. message = '{message}'"
75-
)
76-
}
77-
}
78-
}
79-
}
80-
8164
impl From<RunnerError> for RuntimeError {
8265
fn from(value: RunnerError) -> Self {
8366
Self::KeepState {

0 commit comments

Comments
 (0)