From 697202b0b1c7c02208c620f96c608e0817d079dd Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 3 Jun 2025 16:01:18 +0200 Subject: usage: allow dying without writing an error message 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 use `exit(128)`, which is easy to get wrong and leaves magic numbers all over our codebase. Teach `die_message_builtin()` to not print any error when passed a `NULL` pointer as error string. Like this, such users can now call `die(NULL)` to achieve the same result without any hardcoded error codes. Adapt a couple of builtins to use this new pattern to demonstrate that there is a need for such a helper. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- usage.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'usage.c') diff --git a/usage.c b/usage.c index 38b46bbbfe..cd7b57d644 100644 --- a/usage.c +++ b/usage.c @@ -67,6 +67,8 @@ static NORETURN void usage_builtin(const char *err, va_list params) static void die_message_builtin(const char *err, va_list params) { + if (!err) + return; trace2_cmd_error_va(err, params); vreportf(_("fatal: "), err, params); } -- cgit v1.3-5-g9baa