Re: [PATCH v2 2/6] usage.c: add a non-fatal bug() function to go with BUG()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 1, 2022, 18:50 UTC
- Message-ID
- <xmqqo7zcrzfn.fsf@gitster.g>
- In-Reply-To
- <patch-v2-2.6-2d0527f86dc-20220531T164806Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Unlike the code this replaces we'll log to trace2 with this new bug() > function (as with other usage.c functions, including BUG()),
I do not terribly mind repeated fprintf(stderr, ...) or error() in a loop, but this aspect of the change is probably among the two things that make the series shine (the other obviously being bug_if() which allows us to lose the "did we see any bug?" counter).
Show 8 quoted lines
> Any caller to bug() can follow up such calls with BUG_if_bug(), > which will BUG() out (i.e. abort()) if there were any preceding calls > to bug(), callers can also decide not to call BUG_if_bug() and leave > the resulting BUG() invocation until exit() time. There are currently > no bug() API users that don't call BUG_if_bug() themselves after a > for-loop, but allowing for not calling BUG_if_bug() keeps the API > flexible. As the tests and documentation here show we'll catch missing > BUG_if_bug() invocations in our exit() wrapper.
OK.
Show 6 quoted lines
> I'd previously proposed this as part of another series[1], in that > use-case we ended thinking a BUG() would be better (and eventually > 96e41f58fe1 (fsck: report invalid object type-path combinations, > 2021-10-01) ended up with neither). Here though we'll end up > converting various existing code that was already doing what we're > doing better with this new API.
I think the last paragraph is an after-three-dash material.