git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/4] usage.c: add a die_message() routine

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 6, 2021, 19:42 UTC
Message-ID
<xmqqee6pfrkd.fsf@gitster.g>
In-Reply-To
<patch-1.4-5a9ab85fa56-20211206T165221Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> +int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));
This probalby makes sense (we'll need to see the caller first).
Show 5 quoted lines
> +static void die_message_builtin(const char *err, va_list params)
> +{
> +	trace2_cmd_error_va(err, params);
> +	vreportf("fatal: ", err, params);
> +}

I thought the convention was *not* that we name the variant that takes va_list with _builtin suffix, rather, I thought that the convention is that ones with the _builtin suffix are meant to be override-able by other code.

Show 14 quoted lines
>  /*
>   * We call trace2_cmd_error_va() in the below functions first and
>   * expect it to va_copy 'params' before using it (because an 'ap' can
> @@ -62,10 +68,7 @@ static NORETURN void usage_builtin(const char *err, va_list params)
>   */
>  static NORETURN void die_builtin(const char *err, va_list params)
>  {
> -	trace2_cmd_error_va(err, params);
> -
> -	vreportf("fatal: ", err, params);
> -
> +	die_message_builtin(err, params);
>  	exit(128);
>  }

And by making die() and die_message() both override-able, doesn't it cause confusion on the caller's end which one should get replaced? Or with die_message being overridable, we should rewrite the ones that override die() to instead override die_message()?

It also makes readers wonder why this is not
	exit(die_message(err, params));

which I take it a sign that this new API is overly loose to allow a simple single thing to be done in multiple ways. Perhaps as the series progresses, the picture might improve, but if that is the case, perhaps the presentation order needs to be rethought. E.g. start without the _builtin that implies override-ability, convert the existing code that can benefit from calling die_message(), and then finally introduce _builtin that is merely an implementation detail, or something like that, perhaps?

In any case, the first step in this four patch series is not enough to evaluate if this step makes sense, so let's keep reading.

Show 14 quoted lines
> @@ -211,6 +214,17 @@ void NORETURN die_errno(const char *fmt, ...)
>  	va_end(params);
>  }
>  
> +#undef die_message
> +int die_message(const char *err, ...)
> +{
> +	va_list params;
> +
> +	va_start(params, err);
> +	die_message_builtin(err, params);
> +	va_end(params);
> +	return 128;
> +}
OK.
Thanks.
>  #undef error_errno
>  int error_errno(const char *fmt, ...)
>  {
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 5 of 22 in “usage API: Add and use die_message()”
  1. 0/4 usage API: Add and use die_message()Ævar Arnfjörð Bjarmason, Dec 6, 2021
  2. 2/4 usage.c API users: use die_message() where appropriateÆvar Arnfjörð Bjarmason, Dec 6, 2021
  3. Junio C HamanoDec 6, 2021
  4. 1/4 usage.c: add a die_message() routineÆvar Arnfjörð Bjarmason, Dec 6, 2021
  5. Junio C HamanoDec 6, 2021
  6. Junio C HamanoDec 6, 2021
  7. 4/4 config API: don't use vreportf(), make it static in usage.cÆvar Arnfjörð Bjarmason, Dec 6, 2021
  8. Junio C HamanoDec 6, 2021
  9. Ævar Arnfjörð BjarmasonDec 7, 2021
  10. 3/4 usage.c + gc: add and use a die_message_errno()Ævar Arnfjörð Bjarmason, Dec 6, 2021
  11. Junio C HamanoDec 6, 2021
  12. 0/6 usage API: Add and use die_message()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  13. 1/6 usage.c: add a die_message() routineÆvar Arnfjörð Bjarmason, Dec 7, 2021
  14. 2/6 usage.c API users: use die_message() for "fatal :" + exit 128Ævar Arnfjörð Bjarmason, Dec 7, 2021
  15. 3/6 usage.c API users: use die_message() for error() + exit 128Ævar Arnfjörð Bjarmason, Dec 7, 2021
  16. 4/6 gc: return from cmd_gc(), don't call exit()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  17. 5/6 usage.c + gc: add and use a die_message_errno()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  18. 6/6 config API: use get_error_routine(), not vreportf()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  19. Junio C HamanoDec 7, 2021
  20. Jonathan TanDec 22, 2021
  21. Junio C HamanoDec 22, 2021
  22. Ævar Arnfjörð BjarmasonDec 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.