From f3d85714395f920e21b5f7b33aab322caf7661aa Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Mon, 24 May 2021 14:57:11 +0200 Subject: [PATCH 1/2] Improve error messages --- src/bin/cli/recovery/tally.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bin/cli/recovery/tally.rs b/src/bin/cli/recovery/tally.rs index 4d904ce5..bd745010 100644 --- a/src/bin/cli/recovery/tally.rs +++ b/src/bin/cli/recovery/tally.rs @@ -39,6 +39,12 @@ pub enum Error { #[error("Block0 should be provided either from a path (block0-path) or an url (block0-url)")] Block0Unavailable, + + #[error("Could not load persistent logs from path: {0}")] + PersistenLogsLoadingError(std::io::Error), + + #[error("Could not load block0: {0}")] + Block0LoadingError(std::io::Error), } /// Recover the tally from fragment log files and the initial preloaded block0 binary file. @@ -70,12 +76,12 @@ pub struct Replay { fn read_block0(path: PathBuf) -> Result { let reader = std::fs::File::open(path)?; - Ok(Block::deserialize(BufReader::new(reader))?) + Block::deserialize(BufReader::new(reader)).map_err(Error::Block0LoadingError) } fn load_block0_from_url(url: Url) -> Result { let block0_body = reqwest::blocking::get(url)?.bytes()?; - Ok(Block::deserialize(BufReader::new(&block0_body[..]))?) + Block::deserialize(BufReader::new(&block0_body[..])).map_err(Error::Block0LoadingError) } impl Replay { @@ -98,7 +104,8 @@ impl Replay { return Err(Error::Block0Unavailable); }; - let fragments = load_persistent_fragments_logs_from_folder_path(&logs_path)?; + let fragments = load_persistent_fragments_logs_from_folder_path(&logs_path) + .map_err(Error::PersistenLogsLoadingError)?; let (ledger, failed) = recover_ledger_from_logs(&block0, fragments)?; if !failed.is_empty() { From 6dcf4d486308a07d53dfa1b5a6ea755b5f4c824a Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Tue, 25 May 2021 10:29:25 +0200 Subject: [PATCH 2/2] use Error::source --- src/bin/cli/recovery/tally.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/cli/recovery/tally.rs b/src/bin/cli/recovery/tally.rs index bd745010..031e2e61 100644 --- a/src/bin/cli/recovery/tally.rs +++ b/src/bin/cli/recovery/tally.rs @@ -40,11 +40,11 @@ pub enum Error { #[error("Block0 should be provided either from a path (block0-path) or an url (block0-url)")] Block0Unavailable, - #[error("Could not load persistent logs from path: {0}")] - PersistenLogsLoadingError(std::io::Error), + #[error("Could not load persistent logs from path")] + PersistenLogsLoadingError(#[source] std::io::Error), - #[error("Could not load block0: {0}")] - Block0LoadingError(std::io::Error), + #[error("Could not load block0")] + Block0LoadingError(#[source] std::io::Error), } /// Recover the tally from fragment log files and the initial preloaded block0 binary file.