mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:29:40 +00:00
util: Clarify the assertion message in assertion failures (Assert, Assume, etc.) #35461
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35461
Loading…
Reference in a new issue
No description provided.
Delete branch "2606-assert-msg"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Clarify the message in case of assertion failures. Additionally unify the behavior of
NONFATAL_UNREACHABLEw.r.t. abort handling.Motivation: This was discussed in https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3303436384
The error message generated by
Assert,Assume, andCHECK_NONFATALcontains the failing assertion condition text, but it's unclear whether that's the failed expectation or the actual case.For example,
"Internal bug detected: pindex != nullptr"in fact means that what happened was
pindex == nullptr.Clarify the situation, by inserting "`%s` check failed".
The above example is now:
"Internal bug detected: `pindex != nullptr` check failed"which is more unambiguous.
Additionally, change
NONFATAL_UNREACHABLEto behave likeCHECK_NONFATAL, and honor the special abort setting (G_ABORT_ON_FAILED_ASSUME).The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
Added a test update (following CI failures), condensed util_check test.
Concept ACK, it's a tiny difference that we don't often expect to encounter, but when we do, it better tell us a realistic story.
Left a few nits about slightly clearer phrasing and leaving the new formatter private.
Local patch
I don't particularly like the double colon and starting with capital letters in the middle, please consider avoiding the two stacked labels by adding the text after the failure, e.g:
Could this test the note about non-assert errors directly? Checking NONFATAL_UNREACHABLE keeps the coverage tied to the behavior reviewers need to preserve, instead of only exercising the constructor plumbing.
Could we avoid adding a public
NonFatalCheckErrorfactory? The new formatting is only used by Assert, Assume, and CHECK_NONFATAL, so a helper for the formatted string keeps the generic exception constructor as the only public error API:Should the aborting assertion path use the same clarified wording? Without this, a normal fatal Assert still prints the old Assertion 'condition' failed shape while the exception path says the check failed.
Thanks for reviewing, @l0rinc; suggestions applied. Summary of changes:
assertion_fail, for the non-test-only abort path, also use the same wording.NONFATAL_UNREACHABLE(no assert).(
git diff d46f1fae63ab8d81731ccf0a563119d9edeeeef8 00b0b0f68a825864481103a16caf2a64559f6951)Good point. Unfortunately, this is not possible/easy to test in a unit test (due to the abort).
Forgot about this one, please ping me next time if I don't reply in time (thanks @sedited)
Single quotes around a stringized check collide with character literals in real conditions such as
Assert(cmd.at(0) != '-'), yielding... 'cmd.at(0) != '-'' check failed.Could we rather use backticks as the outer delimiters so the condition remains visually distinct?
The fatal path currently renders "Assertion failed:
<condition>check failed", repeating the same outcome around the condition.Could we render "Assertion
<condition>check failed" once?Thanks for the review, @l0rinc; minor message string changes applied.
git diff 952c64ca50be450ed6288ca85a5a092a85001b42 4b63136bea857e8133c0ff3885fa9ec8d83c03adGood point, applied.
Applied.
🚧 At least one of the CI tasks failed.
Task
Alpine (musl): https://github.com/bitcoin/bitcoin/actions/runs/33526907826/job/99919961765LLM reason (✨ experimental): CI failed due to a compiler crash (internal compiler error: Segmentation fault) while building the fuzz target (
cmpctblock.cpp).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
tested ACK 4b63136bea857e8133c0ff3885fa9ec8d83c03ad
The Alpine failure seems unrelated.
The PR description still shows the old
Failed: '<condition>'wording and should be updated to match the current output.lgtm, left two nits
nit: Probably no need to repeat this. Could just adjust the above?
Since you are adding this test, I wonder if the impl should be
#define NONFATAL_UNREACHABLE inline_check_non_fatal(false, current(), "unreachable"), so thatG_ABORT_ON_FAILED_ASSUMEis recognized, just like forCHECK_NONFATAL.Done. (Thanks for the hint; commit message was updated but not the PR desc.)
Thanks for the comments, @maflcko . One nit applied, the other I've tried, but haven't included currently.
Applied.
This suggestion makes sense, however I'm a bit reluctant to include it in this PR, which is only about message rewording.
I did the suggestion here:
github.com/optout21/bitcoin@5ac866eb21Please advise (change it / make new PR with it / include in this PR).
I really think this can just be a call to
inline_check_non_fatal(false, current(), "unreachable")with the benefits:G_ABORT_ON_FAILED_ASSUMElogic ever changes again in the future, it is more likely to apply to all places. (Less code, logic and functions to keep track of)falseliteral by itself."unreachable"string is fine and sufficient for a dev-only debug-only string.Personally I think it is fine to cycle this into this pull, but no strong opinion.
A technicality: the
inline_check_non_fatalwas duplicated into a[[noreturn]]check_non_fatal_unreachableto avoid the compiler giving "control reaches end of non-void function [-Wreturn-type]" warnings in a few places whereNONFATAL_UNREACHABLEis used. While the macro was a simplethrow, it could be used as a last statement in a non-void method; with the newifthis is not clear for the compiler, hence the need for a[[noreturn]]marker (which cannot be applied oninline_check_non_fatal).Right. In that case, it could make sense to have a single
[[noreturn]] void check_non_fatal_fai(const std::source_location& loc, std::string_view err_msg);helper. And then call it in both places:check_non_fatal_fai(loc, assertion);#define NONFATAL_UNREACHABLE check_non_fatal_fai( current(), "unreachable")Reworked based on @maflcko's suggestion, and unified the non-fatal unreachable and check behavior, so that unreachable also honors special abort setting (G_ABORT_ON_FAILED_ASSUME).
Added two more commits (but also adjusted the first to be in sync with the latter ones).
g_detail_test_only_CheckFailuresAreExceptionsNotAbortsis set).G_ABORT_ON_FAILED_ASSUMEhas been extracted into a new helpercheck_non_fatal_fail(), so it can be reused.assertion_fail()has been renamed to the more descriptiveinternal_abort_helper().Ready for review. CI failure seems unrelated (MacOS, device out of space).
Suggestion applied.
Please update the PR description after this change
code review reACK
6494a7e1c8The PR description still needs update to use backticks and about
NONFATAL_UNREACHABLEnot being affectedDescription updated, remaining inconsistencies fixed, thanks.
Still awaiting review.
Base:
4303f3b7f0775cdbbe77faddf142e1e44fa590caHead:
81fde00cc7ff2c5ae85e8601d8b780ddde7dc2a6Findings
Suggestions
Test the abort path without the exception override (src/test/util_check_tests.cpp:44, head)
This test enables the exception override before calling
NONFATAL_UNREACHABLE(). With aborts enabled,internal_abort_helper()then throws instead of aborting, so the test checks the diagnostic but not the abort behavior. It would still pass if the abort-policy branch were removed. Keep this diagnostic test and add a subprocess or death test with the override disabled in an abort-enabled configuration.Review coverage was incomplete.
Review limitations
Full review report
review ACK
6494a7e1c8🍅Show signature
Signature:
nit in
0d67983acd: I think users will see that the program aborted after writing this, so theAssertion:could also be removed. This means the msgs will be:blacheck failed.which seems fine.
nit in
6494a7e1c8: This is my fault for suggesting the name, but I think a better name would beinternal_non_fatal_helper. with the docstring:(like above)
There is no need to list all call sites. If someone wanted to know them, they could grep.
6494a7e1c8: SameI think it would be good to keep the docs symmetric with
Assumewhich uses the wording "In debug builds it behaves ...`. So the wording here could simply be: "In debug builds an abort is triggered"Happy to re-review if you take the suggestions
@maflcko, thanks for review suggestions, reviewed and applied all.
git range-diff 6494a7e1c863321a5d787ff0e50a51a2e34e9970...704ce3a7adb7d2b67082c5fe8fc328a2d2d43891Good point, taken
Done
Done
Done
Could you rebase and update
util_not_null_teststo expectInternal bug detected: `m_ptr != nullptr` check failed? The stale expectation is causing the CI failures.Please also drop the description's
Note: … are not affectedsentence, since theNONFATAL_UNREACHABLEmessage changes tounreachable.A recently introduced unit test failed in CI (
util_not_null_tests). Rebased and adjusted the test.Also adjusted the description, according to @l0rinc's finding.
🚧 At least one of the CI tasks failed.
Task
macOS native: https://github.com/bitcoin/bitcoin/actions/runs/39477470807/job/118817050199LLM reason (✨ experimental): CI failed because
util_not_null_testshad a failing exception check incheck_null_smart_pointer(theHasReasonvalidation raisedNonFatalCheckError).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
ACK
81fde00cc7Thanks for the quick updates!
review ACK
81fde00cc7🎷Show signature
Signature:
ACK
81fde00cc7