Skip to content

Commit

Permalink
better era error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghubertpalo committed Feb 23, 2023
1 parent e53e516 commit 943bf59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 0 additions & 3 deletions mithril-aggregator/src/runtime/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ pub enum RuntimeError {
#[error("signer registration error: {0}")]
SignerRegistration(#[from] SignerRegistrationError),

#[error("era not supported: {0}")]
EraNotSupported(String),

#[error("general error: {0}")]
General(Box<dyn StdError + Sync + Send>),
}
6 changes: 5 additions & 1 deletion mithril-common/src/era/era_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl EraEpochToken {
/// software.
pub fn get_current_supported_era(&self) -> Result<SupportedEra, UnsupportedEraError> {
SupportedEra::from_str(&self.current_era.name)
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))
}

/// Return the [EraMarker] of the current Era.
Expand All @@ -75,7 +76,10 @@ impl EraEpochToken {
/// for upgrade.
pub fn get_next_supported_era(&self) -> Result<Option<SupportedEra>, UnsupportedEraError> {
match self.next_era.as_ref() {
Some(marker) => Ok(Some(SupportedEra::from_str(&marker.name)?)),
Some(marker) => Ok(Some(
SupportedEra::from_str(&marker.name)
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))?,
)),
None => Ok(None),
}
}
Expand Down
15 changes: 14 additions & 1 deletion mithril-common/src/era/supported_era.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;

/// Error related to [SupportedEra] String parsing implementation.
pub type UnsupportedEraError = strum::ParseError;
#[derive(Debug, Error)]
#[error("Unsupported Era '{era}'.")]
pub struct UnsupportedEraError {
era: String,
}

impl UnsupportedEraError {
pub fn new(era: &str) -> Self {
Self {
era: era.to_owned(),
}
}
}

/// The era that the software is running or will run
#[derive(
Expand Down

0 comments on commit 943bf59

Please sign in to comment.