Skip to content

Commit ed098f1

Browse files
authored
Merge pull request #1232 from input-output-hk/damien/798/implement-anyhow-for-artifact-builder
Implement anyhow context for artifact builder
2 parents 0438765 + ac228e4 commit ed098f1

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.3.90"
3+
version = "0.3.91"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use async_trait::async_trait;
23
use semver::Version;
34
use slog_scope::{debug, warn};
@@ -23,8 +24,8 @@ use mithril_common::{
2324
#[derive(Debug, Error)]
2425
pub enum CardanoImmutableFilesFullArtifactError {
2526
/// Protocol message part is missing
26-
#[error("Missing protocol message: '{0}'.")]
27-
MissingProtocolMessage(String),
27+
#[error("Missing protocol message for beacon: '{0}'.")]
28+
MissingProtocolMessage(Beacon),
2829
}
2930

3031
/// A [CardanoImmutableFilesFullArtifact] builder
@@ -62,9 +63,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {
6263
let snapshot_digest = protocol_message
6364
.get_message_part(&ProtocolMessagePartKey::SnapshotDigest)
6465
.ok_or_else(|| {
65-
CardanoImmutableFilesFullArtifactError::MissingProtocolMessage(format!(
66-
"no digest message part found for beacon '{beacon:?}'."
67-
))
66+
CardanoImmutableFilesFullArtifactError::MissingProtocolMessage(beacon.clone())
6867
})?;
6968
let snapshot_name = format!(
7069
"{}-e{}-i{}.{}.{}",
@@ -117,10 +116,9 @@ impl CardanoImmutableFilesFullArtifactBuilder {
117116
.protocol_message
118117
.get_message_part(&ProtocolMessagePartKey::SnapshotDigest)
119118
.ok_or_else(|| {
120-
CardanoImmutableFilesFullArtifactError::MissingProtocolMessage(format!(
121-
"message part 'digest' not found for snapshot '{}'.",
122-
ongoing_snapshot.get_file_path().display()
123-
))
119+
CardanoImmutableFilesFullArtifactError::MissingProtocolMessage(
120+
certificate.beacon.clone(),
121+
)
124122
})?
125123
.to_owned();
126124
let snapshot = Snapshot::new(
@@ -145,8 +143,16 @@ impl ArtifactBuilder<Beacon, Snapshot> for CardanoImmutableFilesFullArtifactBuil
145143
) -> StdResult<Snapshot> {
146144
let ongoing_snapshot = self
147145
.create_snapshot_archive(&beacon, &certificate.protocol_message)
148-
.await?;
149-
let locations = self.upload_snapshot_archive(&ongoing_snapshot).await?;
146+
.await
147+
.with_context(|| {
148+
"Cardano Immutable Files Full Artifact Builder can not create snapshot archive"
149+
})?;
150+
let locations = self
151+
.upload_snapshot_archive(&ongoing_snapshot)
152+
.await
153+
.with_context(|| {
154+
format!("Cardano Immutable Files Full Artifact Builder can not upload snapshot archive to path: '{:?}'", ongoing_snapshot.get_file_path())
155+
})?;
150156

151157
let snapshot = self
152158
.create_snapshot(certificate, &ongoing_snapshot, locations)

mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ use mithril_common::{
1313
/// Error linked to [MithrilStakeDistributionArtifactBuilder].
1414
#[derive(Debug, Error)]
1515
pub enum MithrilStakeDistributionArtifactBuilderError {
16-
/// Could not get protocol parameters
17-
#[error(
18-
"Could not build Mithril Stake Distribution artifact, no protocol parameters available."
19-
)]
20-
NoProtocolParameters(),
16+
/// Protocol parameters are missing
17+
#[error("Missing protocol parameter for epoch: '{0}'.")]
18+
MissingProtocolParameters(Epoch),
2119
}
20+
2221
/// A [MithrilStakeDistributionArtifact] builder
2322
pub struct MithrilStakeDistributionArtifactBuilder {
2423
multi_signer: Arc<RwLock<dyn MultiSigner>>,
@@ -35,16 +34,15 @@ impl MithrilStakeDistributionArtifactBuilder {
3534
impl ArtifactBuilder<Epoch, MithrilStakeDistribution> for MithrilStakeDistributionArtifactBuilder {
3635
async fn compute_artifact(
3736
&self,
38-
beacon: Epoch,
37+
epoch: Epoch,
3938
_certificate: &Certificate,
4039
) -> StdResult<MithrilStakeDistribution> {
4140
let multi_signer = self.multi_signer.read().await;
42-
let protocol_parameters = multi_signer
43-
.get_next_protocol_parameters()
44-
.await?
45-
.ok_or_else(MithrilStakeDistributionArtifactBuilderError::NoProtocolParameters)?;
41+
let protocol_parameters = multi_signer.get_next_protocol_parameters().await?.ok_or(
42+
MithrilStakeDistributionArtifactBuilderError::MissingProtocolParameters(epoch),
43+
)?;
4644
Ok(MithrilStakeDistribution::new(
47-
beacon,
45+
epoch,
4846
multi_signer.get_next_signers_with_stake().await?,
4947
&protocol_parameters.into(),
5048
))

0 commit comments

Comments
 (0)