Replace try_method! macro with an explicit predicate and inline matches#801
Open
demoray wants to merge 1 commit into
Open
Replace try_method! macro with an explicit predicate and inline matches#801demoray wants to merge 1 commit into
demoray wants to merge 1 commit into
Conversation
succeed-and-return-from-caller, fail-fast-and-return-from-caller, or evaluate to a Box<Error> for aggregation. Two of the three reached into the enclosing function's control flow, so `let crash = Extract the disk-usage special-case into a named predicate `Error::is_disk_usage_exceeded()` and rewrite the three call sites as explicit `match` arms. Behavior is unchanged: on success, return `Ok(())`; on a disk-usage rejection, surface that error immediately; otherwise box the error for aggregation into `AllSourcesFailed`. The macro is deleted. Verified with: - cargo fmt --check - cargo clippy --all-features --all-targets -- -D warnings - cargo test --all-features
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
try_method!insrc/snapshot.rshad three exit paths embedded inone expression: succeed-and-return-from-caller, fail-fast-and-return-
from-caller, or evaluate to a
Box<Error>for aggregation. Two of thethree reached into the enclosing function's control flow, so reading
looked like assignment but might never bind. That's the kind of
hidden control flow macros should avoid.
Extract the disk-usage special case into a named predicate on
Error,and rewrite the three call sites in
Snapshot::create()as explicitmatcharms. Behavior is unchanged: success returns early, adisk-usage rejection surfaces immediately, and any other failure is
boxed and aggregated into
AllSourcesFailed { crash, kcore, devmem }.The macro is deleted.
Wins: every
returnis visible at its call site; the predicate hasa name and is testable in isolation; no macros hiding control flow.
Verified with:
cargo fmt --checkcargo clippy --all-features --all-targets -- -D warningscargo test --all-features