Skip to content

Commit 943bf59

Browse files
committed
better era error messages
1 parent e53e516 commit 943bf59

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

mithril-aggregator/src/runtime/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ pub enum RuntimeError {
6060
#[error("signer registration error: {0}")]
6161
SignerRegistration(#[from] SignerRegistrationError),
6262

63-
#[error("era not supported: {0}")]
64-
EraNotSupported(String),
65-
6663
#[error("general error: {0}")]
6764
General(Box<dyn StdError + Sync + Send>),
6865
}

mithril-common/src/era/era_reader.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl EraEpochToken {
5757
/// software.
5858
pub fn get_current_supported_era(&self) -> Result<SupportedEra, UnsupportedEraError> {
5959
SupportedEra::from_str(&self.current_era.name)
60+
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))
6061
}
6162

6263
/// Return the [EraMarker] of the current Era.
@@ -75,7 +76,10 @@ impl EraEpochToken {
7576
/// for upgrade.
7677
pub fn get_next_supported_era(&self) -> Result<Option<SupportedEra>, UnsupportedEraError> {
7778
match self.next_era.as_ref() {
78-
Some(marker) => Ok(Some(SupportedEra::from_str(&marker.name)?)),
79+
Some(marker) => Ok(Some(
80+
SupportedEra::from_str(&marker.name)
81+
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))?,
82+
)),
7983
None => Ok(None),
8084
}
8185
}

mithril-common/src/era/supported_era.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
use serde::{Deserialize, Serialize};
22
use strum::IntoEnumIterator;
33
use strum_macros::{Display, EnumIter, EnumString};
4+
use thiserror::Error;
45

56
/// Error related to [SupportedEra] String parsing implementation.
6-
pub type UnsupportedEraError = strum::ParseError;
7+
#[derive(Debug, Error)]
8+
#[error("Unsupported Era '{era}'.")]
9+
pub struct UnsupportedEraError {
10+
era: String,
11+
}
12+
13+
impl UnsupportedEraError {
14+
pub fn new(era: &str) -> Self {
15+
Self {
16+
era: era.to_owned(),
17+
}
18+
}
19+
}
720

821
/// The era that the software is running or will run
922
#[derive(

0 commit comments

Comments
 (0)