Skip to content

Commit 805dd40

Browse files
authored
Merge pull request #1223 from input-output-hk/greg/798/error_refacto_common_era
Use anyhow in Era framework
2 parents 17959ff + 23202d5 commit 805dd40

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl DependenciesBuilder {
734734
era_epoch_token.get_current_supported_era().map_err(|e| {
735735
DependenciesBuilderError::Initialization {
736736
message: "Error while building EraChecker".to_string(),
737-
error: Some(e.into()),
737+
error: Some(e),
738738
}
739739
})?,
740740
era_epoch_token.get_current_epoch(),

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ mod tests {
393393
use mockall::predicate;
394394

395395
use mithril_common::entities::{Epoch, SignedEntityType};
396-
use mithril_common::era::UnsupportedEraError;
397396
use mithril_common::test_utils::fake_data;
398397

399398
use super::super::runner::MockAggregatorRunner;
@@ -793,7 +792,7 @@ mod tests {
793792
.expect_update_era_checker()
794793
.with(predicate::eq(fake_data::beacon()))
795794
.once()
796-
.returning(|_| Err(UnsupportedEraError::new("whatever").into()));
795+
.returning(|_| Err(anyhow!("ERROR")));
797796
runner
798797
.expect_close_signer_registration_round()
799798
.once()

mithril-common/src/era/era_reader.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::anyhow;
12
use async_trait::async_trait;
23
use serde::{Deserialize, Serialize};
34
use std::{str::FromStr, sync::Arc};
@@ -6,7 +7,7 @@ use thiserror::Error;
67
use crate::entities::Epoch;
78
use crate::{StdError, StdResult};
89

9-
use super::{supported_era::UnsupportedEraError, SupportedEra};
10+
use super::SupportedEra;
1011

1112
/// Value object that represents a tag of Era change.
1213
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -57,9 +58,9 @@ impl EraEpochToken {
5758
/// Try to cast the current [EraMarker] to a [SupportedEra]. If it fails,
5859
/// that means the current Era is not supported by this version of the
5960
/// software.
60-
pub fn get_current_supported_era(&self) -> Result<SupportedEra, UnsupportedEraError> {
61+
pub fn get_current_supported_era(&self) -> StdResult<SupportedEra> {
6162
SupportedEra::from_str(&self.current_era.name)
62-
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))
63+
.map_err(|_| anyhow!(format!("Unsupported era '{}'.", &self.current_era.name)))
6364
}
6465

6566
/// Return the [EraMarker] of the current Era.
@@ -76,11 +77,11 @@ impl EraEpochToken {
7677
/// means the coming Era will not be supported by this version of the
7778
/// software. This mechanism is used to issue a warning to the user asking
7879
/// for upgrade.
79-
pub fn get_next_supported_era(&self) -> Result<Option<SupportedEra>, UnsupportedEraError> {
80+
pub fn get_next_supported_era(&self) -> StdResult<Option<SupportedEra>> {
8081
match self.next_era.as_ref() {
8182
Some(marker) => Ok(Some(
8283
SupportedEra::from_str(&marker.name)
83-
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))?,
84+
.map_err(|_| anyhow!(format!("Unsupported era '{}'.", &marker.name)))?,
8485
)),
8586
None => Ok(None),
8687
}

mithril-common/src/era/supported_era.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
use serde::{Deserialize, Serialize};
22
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
3-
use thiserror::Error;
4-
5-
/// Error related to [SupportedEra] String parsing implementation.
6-
#[derive(Debug, Error)]
7-
#[error("Unsupported Era '{era}'.")]
8-
pub struct UnsupportedEraError {
9-
era: String,
10-
}
11-
12-
impl UnsupportedEraError {
13-
/// Create a new Era Error
14-
pub fn new(era: &str) -> Self {
15-
Self {
16-
era: era.to_owned(),
17-
}
18-
}
19-
}
203

214
/// The era that the software is running or will run
225
#[derive(

0 commit comments

Comments
 (0)