From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Bagas Sanjaya <bagasdotme@gmail.com>,
Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Subject: Re: [PATCH 1/5] usage.c: add a non-fatal bug() function to go with BUG()
Date: Thu, 26 May 2022 09:59:20 +0200 [thread overview]
Message-ID: <220526.86fskw7mbv.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <xmqqh75d2aif.fsf@gitster.g>
On Wed, May 25 2022, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> +/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */
>>> +extern int bug_called_must_BUG;
>>
>> I am not sure about the name, ...
>
> I finally figured out why I found this name so disturbing. This is
> written from the viewpoint of somebody who is trying to catch a
> programmer's error of calling bug() without calling BUG_if_bug();
> it is not named to help the users of API to understand it better.
I named it like that to indicate a "lesser bug", I think BUG_if_bug()
came later, because ...
> I wonder if it makes sense to make the call to BUG_if_bug() totally
> optional. The rule becomes slightly different:
>
> * You can call bug() zero or more times. It issues a fatal error
> message, and internally remembers the fact that we detected a
> programming error that invalidates the execution of this program,
> without immediately terminating the program.
>
> * When you exit() from the program, the runtime consults that "did
> we call bug()?" record and makes the program exit with known exit
> code (we could arrange it to abort() just like BUG, but I'd
> prefer controlled crash).
>
> * But it is inconvenient to always keep going, after you may have
> called one or more bug(), to the normal program completion. So
> there is a helper exit_if_called_bug(), which is an equivalent to
> checking the "did we call bug()?" record and calling exit().
>
> By making BUG_if_bug() optional, we can lose a handful of lines from
> the test helper, because it makes it a non-issue to exit the program
> without calling it.
I don't think we should do it like that and keep it a BUG() not to call
BUG_if_bug() when we hit exit(), because e.g. in the case of
parse-options.c once we have the a bad "struct options" we don't want to
continue, as we might segfault, or have other bad behavior etc. So we'd
like to BUG() out as soon as possible.
That's how we use BUG() itself, i.e. we think the program execution is
bad and we immediately abort(), the new bug() makes a small concession
that we may be OK for a little while (e.g. while looping over the
options), but would like to BUG() out immediately after that.
next prev parent reply other threads:[~2022-05-26 8:03 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-21 17:14 [PATCH 0/5] usage API: add and use a bug() + BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-21 17:14 ` [PATCH 1/5] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-05-25 20:55 ` Junio C Hamano
2022-05-26 4:17 ` Junio C Hamano
2022-05-26 7:59 ` Ævar Arnfjörð Bjarmason [this message]
2022-05-26 16:55 ` Junio C Hamano
2022-05-26 18:29 ` Ævar Arnfjörð Bjarmason
2022-05-26 18:55 ` Junio C Hamano
2022-05-31 16:52 ` Ævar Arnfjörð Bjarmason
2022-05-27 17:03 ` Josh Steadmon
2022-05-27 19:05 ` Junio C Hamano
2022-05-21 17:14 ` [PATCH 2/5] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-05-27 17:03 ` Josh Steadmon
2022-05-21 17:14 ` [PATCH 3/5] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-05-25 21:05 ` Junio C Hamano
2022-05-21 17:14 ` [PATCH 4/5] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-25 21:15 ` Junio C Hamano
2022-05-27 17:04 ` Josh Steadmon
2022-05-27 22:53 ` Andrei Rybak
2022-05-21 17:14 ` [PATCH 5/5] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-05-27 21:29 ` Glen Choo
2022-05-27 17:02 ` [PATCH 0/5] usage API: add and use a bug() + BUG_if_bug() Josh Steadmon
2022-05-31 16:58 ` [PATCH v2 0/6] " Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 1/6] common-main.o: move non-trace2 exit() behavior out of trace2.c Ævar Arnfjörð Bjarmason
2022-06-01 18:37 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 2/6] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-05-31 18:18 ` Glen Choo
2022-06-01 18:50 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 3/6] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 4/6] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-05-31 17:38 ` Josh Steadmon
2022-06-01 18:55 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 5/6] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 6/6] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-06-01 18:52 ` Junio C Hamano
2022-05-31 17:39 ` [PATCH v2 0/6] usage API: add and use a bug() + BUG_if_bug() Josh Steadmon
2022-06-02 12:25 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 1/6] common-main.o: move non-trace2 exit() behavior out of trace2.c Ævar Arnfjörð Bjarmason
2022-06-03 1:19 ` Junio C Hamano
2022-06-07 20:09 ` Josh Steadmon
2022-06-07 21:12 ` Ævar Arnfjörð Bjarmason
2022-06-07 22:05 ` Josh Steadmon
2022-06-02 12:25 ` [PATCH v3 2/6] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 3/6] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 4/6] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 5/6] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 6/6] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-06-02 19:54 ` Junio C Hamano
2022-06-02 16:56 ` [PATCH v3 0/6] usage API: add and use a bug() + BUG_if_bug() Glen Choo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=220526.86fskw7mbv.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=chakrabortyabhradeep79@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.