Subject: Re: [PATCH 1/5] usage.c: add a non-fatal bug() function to go with BUG()

From: Junio C Hamano <[email-masked]>
Date: Fri, 27 May 2022 12:05:28 -0700

Josh Steadmon <[email-masked]> writes:

> On 2022.05.21 19:14, Ævar Arnfjörð Bjarmason wrote:
>> Add a bug() function to use in cases where we'd like to indicate a
>> runtime BUG(), but would like to deref the BUG() call because we're
>
> Typo: I assume you meant s/deref/defer/
>
>
> [snip]
>
>> diff --git a/trace2.c b/trace2.c
>> index e01cf77f1a8..d49d5d5a082 100644
>> --- a/trace2.c
>> +++ b/trace2.c
>> @@ -211,6 +211,12 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)
>>  
>>  	code &= 0xff;
>>  
>> +	if (bug_called_must_BUG) {
>> +		/* BUG_vfl() calls exit(), which calls us again */
>> +		bug_called_must_BUG = 0;
>> +		BUG("had bug() output above, in addition missed BUG_if_bug() call");
>> +	}
>> +
>>  	if (!trace2_enabled)
>>  		return code;
>
> While it does seem that trace2_cmd_exit_fl() is the only reasonable
> place to put this cleanup code, perhaps it makes sense to rename this
> function and move it out of trace2.c, to more clearly show that it has
> multiple responsibilities now?

Sounds good.  This is to exit() as common_main() is to main(), it
seems to me?