1
1
use slog:: { crit, error, Logger } ;
2
- use std :: fmt :: Display ;
2
+ use thiserror :: Error ;
3
3
4
4
use mithril_common:: entities:: EpochError ;
5
5
use mithril_common:: StdError ;
@@ -8,24 +8,28 @@ use crate::RunnerError;
8
8
9
9
/// RuntimeError
10
10
/// Error kinds tied to their faith in the state machine.
11
- #[ derive( Debug ) ]
11
+ #[ derive( Error , Debug ) ]
12
12
pub enum RuntimeError {
13
13
/// KeepState error means the runtime will keep its state and try to cycle
14
14
/// again.
15
+ #[ error( "An error occurred, runtime state kept. message = '{message}'" ) ]
15
16
KeepState {
16
17
/// Context error message
17
18
message : String ,
18
19
19
20
/// Eventual previous error message
21
+ #[ source]
20
22
nested_error : Option < StdError > ,
21
23
} ,
22
24
/// Critical error means the runtime will exit and the software will return
23
25
/// an error code.
26
+ #[ error( "A critical error occurred, aborting runtime. message = '{message}'" ) ]
24
27
Critical {
25
28
/// Context error message
26
29
message : String ,
27
30
28
31
/// Eventual previous error message
32
+ #[ source]
29
33
nested_error : Option < StdError > ,
30
34
} ,
31
35
}
@@ -57,27 +61,6 @@ impl RuntimeError {
57
61
}
58
62
}
59
63
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
-
81
64
impl From < RunnerError > for RuntimeError {
82
65
fn from ( value : RunnerError ) -> Self {
83
66
Self :: KeepState {
0 commit comments