Skip to content

Commit

Permalink
ledger-tool: Condense repeated error handling (#34439)
Browse files Browse the repository at this point in the history
Several commands call load_and_process_ledger() which can fail in a
number of ways. These callers currently all handle the result in the
same way by matching the return Result:
- The Ok(_) case uses the returned types as normal
- The Err(_) case prints an error message and exits

This error handling is redundant, and a helper could remove the
duplicate code. So, this PR adds a wrapper around that checks the
result and unwraps OR prints error messages and exits.
  • Loading branch information
steviez authored Dec 13, 2023
1 parent 0b6d939 commit 2a67fa8
Show file tree
Hide file tree
Showing 3 changed files with 794 additions and 866 deletions.
22 changes: 22 additions & 0 deletions ledger-tool/src/ledger_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ pub fn get_shred_storage_type(ledger_path: &Path, message: &str) -> ShredStorage
}
}

pub fn load_and_process_ledger_or_exit(
arg_matches: &ArgMatches,
genesis_config: &GenesisConfig,
blockstore: Arc<Blockstore>,
process_options: ProcessOptions,
snapshot_archive_path: Option<PathBuf>,
incremental_snapshot_archive_path: Option<PathBuf>,
) -> (Arc<RwLock<BankForks>>, Option<StartingSnapshotHashes>) {
load_and_process_ledger(
arg_matches,
genesis_config,
blockstore,
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
)
.unwrap_or_else(|err| {
eprintln!("Exiting. Failed to load and process ledger: {err}");
exit(1);
})
}

pub fn load_and_process_ledger(
arg_matches: &ArgMatches,
genesis_config: &GenesisConfig,
Expand Down
Loading

0 comments on commit 2a67fa8

Please sign in to comment.