Skip to content

Commit c6cdaf5

Browse files
committed
3/4 of thiserrors done
1 parent 5ceb16f commit c6cdaf5

File tree

26 files changed

+98
-273
lines changed

26 files changed

+98
-273
lines changed

catalyst-toolbox/src/archive.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use chain_core::{packer::Codec, property::DeserializeFromSlice};
33
use chain_impl_mockchain::{
44
block::Block, chaintypes::HeaderId, fragment::Fragment, transaction::InputEnum,
55
};
6+
use color_eyre::{eyre::bail, Report};
67
use jormungandr_lib::interfaces::{AccountIdentifier, Address};
78

89
use serde::Serialize;
@@ -11,21 +12,6 @@ use std::{collections::HashMap, path::Path};
1112

1213
const MAIN_TAG: &str = "HEAD";
1314

14-
#[derive(Debug, thiserror::Error)]
15-
pub enum Error {
16-
#[error(transparent)]
17-
Storage(#[from] chain_storage::Error),
18-
19-
#[error(transparent)]
20-
Io(#[from] std::io::Error),
21-
22-
#[error(transparent)]
23-
Csv(#[from] csv::Error),
24-
25-
#[error("Only accounts inputs are supported not Utxos")]
26-
UnhandledInput,
27-
}
28-
2915
#[derive(Serialize)]
3016
struct Vote {
3117
fragment_id: String,
@@ -36,7 +22,10 @@ struct Vote {
3622
raw_fragment: String,
3723
}
3824

39-
pub fn generate_archive_files(jormungandr_database: &Path, output_dir: &Path) -> Result<(), Error> {
25+
pub fn generate_archive_files(
26+
jormungandr_database: &Path,
27+
output_dir: &Path,
28+
) -> Result<(), Report> {
4029
let db = chain_storage::BlockStore::file(
4130
jormungandr_database,
4231
HeaderId::zero_hash()
@@ -67,7 +56,7 @@ pub fn generate_archive_files(jormungandr_database: &Path, output_dir: &Path) ->
6756
AccountIdentifier::from(account_id)
6857
.into_address(Discrimination::Production, "ca")
6958
} else {
70-
return Err(Error::UnhandledInput);
59+
bail!("unhandled input")
7160
};
7261
let certificate = tx.as_slice().payload().into_payload();
7362

catalyst-toolbox/src/bin/cli/archive/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use catalyst_toolbox::archive::{generate_archive_files, Error};
1+
use catalyst_toolbox::archive::generate_archive_files;
22

3+
use color_eyre::Report;
34
use structopt::StructOpt;
45

56
use std::path::PathBuf;
@@ -14,7 +15,7 @@ pub struct Archive {
1415
}
1516

1617
impl Archive {
17-
pub fn exec(self) -> Result<(), Error> {
18+
pub fn exec(self) -> Result<(), Report> {
1819
generate_archive_files(&self.jormungandr_database, &self.output_dir)
1920
}
2021
}

catalyst-toolbox/src/bin/cli/logs/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
mod compare;
22
mod sentry;
33

4+
use color_eyre::Report;
45
use structopt::StructOpt;
56

6-
#[derive(thiserror::Error, Debug)]
7-
pub enum Error {
8-
#[error(transparent)]
9-
SentryError(#[from] sentry::Error),
10-
11-
#[error(transparent)]
12-
CompareError(#[from] compare::Error),
13-
}
14-
157
#[derive(StructOpt)]
168
#[structopt(rename_all = "kebab-case")]
179
pub enum Logs {
@@ -22,7 +14,7 @@ pub enum Logs {
2214
}
2315

2416
impl Logs {
25-
pub fn exec(self) -> Result<(), Error> {
17+
pub fn exec(self) -> Result<(), Report> {
2618
match self {
2719
Logs::Sentry(sentry_logs) => sentry_logs.exec()?,
2820
Logs::Compare(compare) => compare.exec()?,

catalyst-toolbox/src/bin/cli/logs/sentry/download.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::Error;
21
use catalyst_toolbox::logs::sentry::{LazySentryLogs, RawLog, SentryLogClient};
2+
use color_eyre::Report;
33
use jcli_lib::utils::io::open_file_write;
44

55
use std::path::PathBuf;
@@ -65,7 +65,7 @@ impl FromStr for Mode {
6565
}
6666

6767
impl Download {
68-
pub fn exec(self) -> Result<(), Error> {
68+
pub fn exec(self) -> Result<(), Report> {
6969
let Self {
7070
url,
7171
token,
@@ -132,7 +132,7 @@ fn request_sentry_logs_and_dump_to_file(
132132
dates: DateFilter,
133133
out: PathBuf,
134134
chunk_size: usize,
135-
) -> Result<(), Error> {
135+
) -> Result<(), Report> {
136136
let client = SentryLogClient::new(url, token);
137137

138138
println!("Starting downloading...");
@@ -159,7 +159,7 @@ fn request_sentry_logs_and_dump_to_file(
159159
Ok(())
160160
}
161161

162-
fn dump_logs_to_json(logs: &[RawLog], out: PathBuf) -> Result<(), Error> {
162+
fn dump_logs_to_json(logs: &[RawLog], out: PathBuf) -> Result<(), Report> {
163163
let file = open_file_write(&Some(out))?;
164164
serde_json::to_writer_pretty(file, logs)?;
165165
Ok(())

catalyst-toolbox/src/bin/cli/logs/sentry/mod.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
mod download;
22
mod stats;
33

4-
use catalyst_toolbox::logs::sentry::Error as SentryLogError;
5-
4+
use color_eyre::Report;
65
use structopt::StructOpt;
76

8-
#[derive(thiserror::Error, Debug)]
9-
pub enum Error {
10-
#[error(transparent)]
11-
SentryLog(#[from] SentryLogError),
12-
13-
#[error(transparent)]
14-
Io(#[from] std::io::Error),
15-
16-
#[error(transparent)]
17-
Json(#[from] serde_json::Error),
18-
}
19-
207
#[derive(StructOpt)]
218
#[structopt(rename_all = "kebab-case")]
229
pub enum SentryLogs {
@@ -27,7 +14,7 @@ pub enum SentryLogs {
2714
}
2815

2916
impl SentryLogs {
30-
pub fn exec(self) -> Result<(), Error> {
17+
pub fn exec(self) -> Result<(), Report> {
3118
match self {
3219
SentryLogs::Download(download) => download.exec(),
3320
SentryLogs::Stats(stats) => stats.exec(),

catalyst-toolbox/src/bin/cli/logs/sentry/stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::Error;
21
use catalyst_toolbox::logs::sentry::{
32
RawLog, RegexMatch, SentryLogsStatChecker, SentryLogsStatsExecutor, Stat,
43
};
4+
use color_eyre::Report;
55
use jcli_lib::utils::io::open_file_read;
66

77
use regex::Regex;
@@ -77,7 +77,7 @@ impl Stats {
7777
SentryLogsStatsExecutor::new(checkers)
7878
}
7979

80-
pub fn exec(self) -> Result<(), Error> {
80+
pub fn exec(self) -> Result<(), Report> {
8181
let mut checker = self.build_checkers();
8282
let logs_reader = open_file_read(&Some(self.file))?;
8383
let logs: Vec<RawLog> = serde_json::from_reader(logs_reader)?;

catalyst-toolbox/src/bin/cli/notifications/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
mod api_params;
22
mod send;
33

4+
use color_eyre::Report;
45
use structopt::StructOpt;
5-
use thiserror::Error;
6-
7-
#[allow(clippy::large_enum_variant)]
8-
#[derive(Debug, Error)]
9-
pub enum Error {
10-
#[error("error reading file, source: {0}")]
11-
FileError(#[from] std::io::Error),
12-
13-
#[error(transparent)]
14-
NotificationError(#[from] catalyst_toolbox::notifications::Error),
15-
}
166

177
#[derive(StructOpt)]
188
#[structopt(rename_all = "kebab-case")]
@@ -21,7 +11,7 @@ pub enum PushNotifications {
2111
}
2212

2313
impl PushNotifications {
24-
pub fn exec(self) -> Result<(), Error> {
14+
pub fn exec(self) -> Result<(), Report> {
2515
use self::PushNotifications::*;
2616
match self {
2717
Send(cmd) => cmd.exec()?,

catalyst-toolbox/src/bin/cli/recovery/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod tally;
22
mod votes;
33

4+
use color_eyre::Report;
45
use structopt::StructOpt;
56

67
#[derive(StructOpt)]
@@ -11,7 +12,7 @@ pub enum Recover {
1112
}
1213

1314
impl Recover {
14-
pub fn exec(self) -> Result<(), tally::Error> {
15+
pub fn exec(self) -> Result<(), Report> {
1516
match self {
1617
Recover::Tally(cmd) => cmd.exec(),
1718
Recover::VotesPrintout(cmd) => cmd.exec(),

catalyst-toolbox/src/bin/cli/recovery/tally.rs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,17 @@
1-
use catalyst_toolbox::recovery::{Replay, ReplayError};
2-
use chain_core::{
3-
packer::Codec,
4-
property::{Deserialize, ReadError},
5-
};
1+
use catalyst_toolbox::recovery::Replay;
2+
use chain_core::{packer::Codec, property::Deserialize};
63
use chain_impl_mockchain::block::Block;
7-
use jcli_lib::utils::{
8-
output_file::{Error as OutputFileError, OutputFile},
9-
output_format::{Error as OutputFormatError, OutputFormat},
4+
use color_eyre::{
5+
eyre::{bail, Context},
6+
Report,
107
};
8+
use jcli_lib::utils::{output_file::OutputFile, output_format::OutputFormat};
119

1210
use std::path::PathBuf;
1311

1412
use reqwest::Url;
1513
use structopt::StructOpt;
1614

17-
#[allow(clippy::large_enum_variant)]
18-
#[derive(thiserror::Error, Debug)]
19-
pub enum Error {
20-
#[error(transparent)]
21-
Replay(#[from] ReplayError),
22-
23-
#[error(transparent)]
24-
Io(#[from] std::io::Error),
25-
26-
#[error(transparent)]
27-
Request(#[from] reqwest::Error),
28-
29-
#[error(transparent)]
30-
Serialization(#[from] serde_json::Error),
31-
32-
#[error(transparent)]
33-
OutputFile(#[from] OutputFileError),
34-
35-
#[error(transparent)]
36-
OutputFormat(#[from] OutputFormatError),
37-
38-
#[error("Block0 should be provided either from a path (block0-path) or an url (block0-url)")]
39-
Block0Unavailable,
40-
41-
#[error("Could not load block0")]
42-
Block0Loading(#[source] ReadError),
43-
}
44-
4515
/// Recover the tally from fragment log files and the initial preloaded block0 binary file.
4616
#[derive(StructOpt)]
4717
#[structopt(rename_all = "kebab")]
@@ -69,18 +39,18 @@ pub struct ReplayCli {
6939
verbose: usize,
7040
}
7141

72-
fn read_block0(path: PathBuf) -> Result<Block, Error> {
42+
fn read_block0(path: PathBuf) -> Result<Block, Report> {
7343
let reader = std::fs::File::open(path)?;
74-
Block::deserialize(&mut Codec::new(reader)).map_err(Error::Block0Loading)
44+
Block::deserialize(&mut Codec::new(reader)).context("block0 loading")
7545
}
7646

77-
fn load_block0_from_url(url: Url) -> Result<Block, Error> {
47+
fn load_block0_from_url(url: Url) -> Result<Block, Report> {
7848
let block0_body = reqwest::blocking::get(url)?.bytes()?;
79-
Block::deserialize(&mut Codec::new(&block0_body[..])).map_err(Error::Block0Loading)
49+
Block::deserialize(&mut Codec::new(&block0_body[..])).context("block0 loading")
8050
}
8151

8252
impl ReplayCli {
83-
pub fn exec(self) -> Result<(), Error> {
53+
pub fn exec(self) -> Result<(), Report> {
8454
let Self {
8555
block0_path,
8656
block0_url,
@@ -96,7 +66,7 @@ impl ReplayCli {
9666
} else if let Some(url) = block0_url {
9767
load_block0_from_url(url)?
9868
} else {
99-
return Err(Error::Block0Unavailable);
69+
bail!("block0 unavailable");
10070
};
10171

10272
let replay = Replay::new(block0, logs_path, output, output_format);

catalyst-toolbox/src/bin/cli/recovery/votes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::tally::Error;
21
use catalyst_toolbox::recovery::tally::{
32
deconstruct_account_transaction, ValidatedFragment, ValidationError, VoteFragmentFilter,
43
};
@@ -9,6 +8,7 @@ use chain_core::{
98
use chain_impl_mockchain::{
109
account::SpendingCounter, block::Block, fragment::Fragment, vote::Payload,
1110
};
11+
use color_eyre::Report;
1212
use jcli_lib::utils::{output_file::OutputFile, output_format::OutputFormat};
1313
use jormungandr_lib::interfaces::load_persistent_fragments_logs_from_folder_path;
1414
use serde::Serialize;
@@ -93,7 +93,7 @@ struct RecoveredVotes {
9393
}
9494

9595
impl VotesPrintout {
96-
pub fn exec(self) -> Result<(), Error> {
96+
pub fn exec(self) -> Result<(), Report> {
9797
let VotesPrintout {
9898
block0_path,
9999
logs_path,

0 commit comments

Comments
 (0)