-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ledger-tool: Bubble up error enum instead of eprintln!() and exit() #34426
Conversation
5ced106
to
4e8bfee
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #34426 +/- ##
=======================================
Coverage 81.8% 81.9%
=======================================
Files 819 819
Lines 221037 221037
=======================================
+ Hits 181028 181052 +24
+ Misses 40009 39985 -24 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. Love the error changes. Also somewhat surprised by the number of cargo fmt changes.
const PROCESS_SLOTS_HELP_STRING: &str = | ||
"The starting slot is either the latest found snapshot slot, or genesis (slot 0) if the \ | ||
--no-snapshot flag was specified or if no snapshots were found. \ | ||
The ending slot is the snapshot creation slot for create-snapshot, the value for \ | ||
--halt-at-slot if specified, or the highest slot in the blockstore."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤌
Yeah, definitely an indicator that we need to break some stuff into sub-functions. For example, the implementation of solana/ledger-tool/src/main.rs Lines 3010 to 3018 in 39f2866
Similarly, After typing the above comments about line counts out, I think I'm going to split this into two PR's:
I don't think we'd backport any of this functionality, but in any case, I think there is a logical split with these two, and it makes the change that actually does a little more (the error enum one) a little less "obfuscated" by being in the same squashed commit as ~1500 lines of |
4e8bfee
to
efbd735
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me. Can you update the PR's title before merging, please?
Problem
The ledger-tool
load_and_process_ledger()
function performs many sub-operations that can fail. The current error handling of printing text and exiting inline adds extra noise to the code that actually does work.Additionally, all of the separate exit points mean that there might be slightly different variations the common text when an unrecoverable error occurs.Summary of Changes
LoadAndProcessLedgerError
enum forload_and_process_ledger()
error conditionsResult<_, LoadAndProcessLedgerError>
Introduce and use wrapper that unwraps or exitsload_and_process_ledger()
Use the wrapper for all previous callers ofload_and_process_ledger()
to remove boilerplate codeThe diff on this one is massive because some match statements were removed andcargo fmt
reduced a lot of indentation. All of the changes introduced bycargo fmt
are in a single commit, so viewing this PR commit-by-commit OR with whitespace hidden (or both) would be my advice.All of the struckthrough items will be handled in a separate PR