Re: [PATCH v3 10/12] usage: allow dying without writing an error message
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 3, 2025, 15:24 UTC
- Message-ID
- <xmqqmsaoq244.fsf@gitster.g>
- In-Reply-To
- <20250602-b4-pks-maintenance-ref-lock-race-v3-10-587d44252dcb@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
> Sometimes code wants to die in a situation where it already has written
> an error message. To use the same error code as `die()` we have to open
> code the code with a call to `exit(128)` in such cases, which is easy to
> get wrong and leaves magical numbers all over our codebase.
> ...
> if (!patch_format) {
> fprintf_ln(stderr, _("Patch format detection failed."));
> - exit(128);
> + die(NULL);It is somewhat surprising that the compiler would not complain with "Hey, a NULL string as printf format string???" given its decl.
NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
As long as we are sure that compilers we care about are OK with this, it is a very nice ergonomics enhancement.