Skip to content

Commit 8730cc6

Browse files
authored
Merge pull request #2858 from input-output-hk/djo/2825/enhance-error-contexts
chore: enhance and align usage of the anyhow across crates
2 parents b3772ac + a4c6b5e commit 8730cc6

File tree

122 files changed

+1299
-653
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1299
-653
lines changed

Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-cardano-database-v2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-cardano-database-v2"
33
description = "Mithril client Cardano database example"
4-
version = "0.0.15"
4+
version = "0.0.16"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-cardano-database-v2/src/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ async fn main() -> MithrilResult<()> {
7575

7676
let latest_hash = cardano_database_snapshots
7777
.first()
78-
.ok_or(anyhow!(
79-
"No Cardano database snapshot could be listed from aggregator: '{}'",
80-
args.aggregator_endpoint
81-
))?
78+
.with_context(|| {
79+
format!(
80+
"No Cardano database snapshot could be listed from aggregator: '{}'",
81+
args.aggregator_endpoint
82+
)
83+
})?
8284
.hash
8385
.as_ref();
8486

85-
let cardano_database_snapshot = client.cardano_database_v2().get(latest_hash).await?.ok_or(
86-
anyhow!("A Cardano database should exist for hash '{latest_hash}'"),
87-
)?;
87+
let cardano_database_snapshot = client
88+
.cardano_database_v2()
89+
.get(latest_hash)
90+
.await?
91+
.with_context(|| format!("A Cardano database should exist for hash '{latest_hash}'"))?;
8892

8993
let unpacked_dir = work_dir.join("unpack");
9094
std::fs::create_dir(&unpacked_dir).unwrap();

examples/client-cardano-database/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-cardano-database"
33
description = "Mithril client Cardano database example"
4-
version = "0.1.38"
4+
version = "0.1.39"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-cardano-database/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,20 @@ async fn main() -> MithrilResult<()> {
7474

7575
let last_digest = snapshots
7676
.first()
77-
.ok_or(anyhow!(
78-
"No snapshots could be listed from aggregator: '{}'",
79-
args.aggregator_endpoint
80-
))?
77+
.with_context(|| {
78+
format!(
79+
"No snapshots could be listed from aggregator: '{}'",
80+
args.aggregator_endpoint
81+
)
82+
})?
8183
.digest
8284
.as_ref();
8385

8486
let snapshot = client
8587
.cardano_database()
8688
.get(last_digest)
8789
.await?
88-
.ok_or(anyhow!("A snapshot should exist for hash '{last_digest}'"))?;
90+
.with_context(|| format!("A snapshot should exist for hash '{last_digest}'"))?;
8991

9092
let unpacked_dir = work_dir.join("unpack");
9193
std::fs::create_dir(&unpacked_dir).unwrap();

examples/client-cardano-stake-distribution/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-cardano-stake-distribution"
33
description = "Mithril client cardano stake distribution example"
4-
version = "0.1.14"
4+
version = "0.1.15"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-cardano-stake-distribution/src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! In this example, the client interacts by default with a real aggregator (`release-preprod`) to get the data.
44
5-
use anyhow::anyhow;
5+
use anyhow::Context;
66
use clap::Parser;
77
use slog::info;
88
use std::{str::FromStr, sync::Arc};
@@ -57,19 +57,21 @@ async fn main() -> MithrilResult<()> {
5757

5858
let last_epoch = cardano_stake_distributions
5959
.first()
60-
.ok_or(anyhow!(
61-
"No Cardano stake distributions could be listed from aggregator: '{}'",
62-
args.aggregator_endpoint
63-
))?
60+
.with_context(|| {
61+
format!(
62+
"No Cardano stake distributions could be listed from aggregator: '{}'",
63+
args.aggregator_endpoint
64+
)
65+
})?
6466
.epoch;
6567

6668
let cardano_stake_distribution = client
6769
.cardano_stake_distribution()
6870
.get_by_epoch(last_epoch)
6971
.await?
70-
.ok_or(anyhow!(
71-
"A Cardano stake distribution should exist for hash '{last_epoch}'"
72-
))?;
72+
.with_context(|| {
73+
format!("A Cardano stake distribution should exist for hash '{last_epoch}'")
74+
})?;
7375
info!(
7476
logger,
7577
"Fetched details of last Cardano stake distribution:\n{cardano_stake_distribution:#?}",

examples/client-mithril-stake-distribution/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-mithril-stake-distribution"
33
description = "Mithril client stake distribution example"
4-
version = "0.2.12"
4+
version = "0.2.13"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-mithril-stake-distribution/src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! In this example, the client interacts by default with a real aggregator (`release-preprod`) to get the data.
44
5-
use anyhow::anyhow;
5+
use anyhow::Context;
66
use clap::Parser;
77
use slog::info;
88
use std::{str::FromStr, sync::Arc};
@@ -57,20 +57,22 @@ async fn main() -> MithrilResult<()> {
5757

5858
let last_hash = mithril_stake_distributions
5959
.first()
60-
.ok_or(anyhow!(
61-
"No Mithril stake distributions could be listed from aggregator: '{}'",
62-
args.aggregator_endpoint
63-
))?
60+
.with_context(|| {
61+
format!(
62+
"No Mithril stake distributions could be listed from aggregator: '{}'",
63+
args.aggregator_endpoint
64+
)
65+
})?
6466
.hash
6567
.as_ref();
6668

6769
let mithril_stake_distribution = client
6870
.mithril_stake_distribution()
6971
.get(last_hash)
7072
.await?
71-
.ok_or(anyhow!(
72-
"A Mithril stake distribution should exist for hash '{last_hash}'"
73-
))?;
73+
.with_context(|| {
74+
format!("A Mithril stake distribution should exist for hash '{last_hash}'")
75+
})?;
7476
info!(
7577
logger,
7678
"Fetched details of last Mithril stake distribution:\n{mithril_stake_distribution:#?}",

examples/client-wasm-nodejs/package-lock.json

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

0 commit comments

Comments
 (0)