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

Re: [PATCH v2 4/6] parse-options.c: use optbug() instead of BUG() "opts" check

From
Josh Steadmon <steadmon@google.com>
Date
May 31, 2022, 17:38 UTC
Message-ID
<YpZSrNM/bZ3i6Yvu@google.com>
In-Reply-To
<patch-v2-4.6-47d384d0ae5-20220531T164806Z-avarab@gmail.com>
On 2022.05.31 18:58, Ævar Arnfjörð Bjarmason wrote:
Show 45 quoted lines
> Change the assertions added in bf3ff338a25 (parse-options: stop
> abusing 'callback' for lowlevel callbacks, 2019-01-27) to use optbug()
> instead of BUG(). At this point we're looping over individual options,
> so if we encounter any issues we'd like to report the offending option.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  parse-options.c | 31 ++++++++++++++++++++-----------
>  1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/parse-options.c b/parse-options.c
> index 78b46ae9698..243016ae30f 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -473,21 +473,30 @@ static void parse_options_check(const struct option *opts)
>  				optbug(opts, "should not accept an argument");
>  			break;
>  		case OPTION_CALLBACK:
> -			if (!opts->callback && !opts->ll_callback)
> -				BUG("OPTION_CALLBACK needs one callback");
> -			if (opts->callback && opts->ll_callback)
> -				BUG("OPTION_CALLBACK can't have two callbacks");
> +			if (!opts->callback && !opts->ll_callback) {
> +				optbug(opts, "OPTION_CALLBACK needs one callback");
> +				break;
> +			}
> +			if (opts->callback && opts->ll_callback) {
> +				optbug(opts, "OPTION_CALLBACK can't have two callbacks");
> +				break;
> +			}
>  			break;
>  		case OPTION_LOWLEVEL_CALLBACK:
> -			if (!opts->ll_callback)
> -				BUG("OPTION_LOWLEVEL_CALLBACK needs a callback");
> -			if (opts->callback)
> -				BUG("OPTION_LOWLEVEL_CALLBACK needs no high level callback");
> +			if (!opts->ll_callback) {
> +				optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs a callback");
> +				break;
> +			}
> +			if (opts->callback) {
> +				optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs no high level callback");
> +				break;
> +			}
>  			break;

A minor point, but I'm not sure I understand why we're adding breaks for the two cases above. In the OPTION_CALLBACK case, the if conditions are mutually exclusive and are followed by an unconditional break, so adding additional breaks seems unnecessary. For the OPTION_LOWLEVEL_CALLBACK case, the conditions are not mutually exclusive, but isn't this exactly the issue that optbug() is intended to address? I.e., wouldn't the caller want to see both optbug()s if both are relevant?

Show 14 quoted lines
>  		case OPTION_ALIAS:
> -			BUG("OPT_ALIAS() should not remain at this point. "
> -			    "Are you using parse_options_step() directly?\n"
> -			    "That case is not supported yet.");
> +			optbug(opts, "OPT_ALIAS() should not remain at this point. "
> +			       "Are you using parse_options_step() directly?\n"
> +			       "That case is not supported yet.");
> +			break;
>  		default:
>  			; /* ok. (usually accepts an argument) */
>  		}
> -- 
> 2.36.1.1100.g16130010d07
> 
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 31 of 49 in “usage API: add and use a bug() + BUG_if_bug()”
  1. 0/5 usage API: add and use a bug() + BUG_if_bug()Ævar Arnfjörð Bjarmason, May 21, 2022
  2. 1/5 usage.c: add a non-fatal bug() function to go with BUG()Ævar Arnfjörð Bjarmason, May 21, 2022
  3. Junio C HamanoMay 25, 2022
  4. Junio C HamanoMay 26, 2022
  5. Ævar Arnfjörð BjarmasonMay 26, 2022
  6. Junio C HamanoMay 26, 2022
  7. Ævar Arnfjörð BjarmasonMay 26, 2022
  8. Junio C HamanoMay 26, 2022
  9. Ævar Arnfjörð BjarmasonMay 31, 2022
  10. Josh SteadmonMay 27, 2022
  11. Junio C HamanoMay 27, 2022
  12. 2/5 parse-options.c: use new bug() API for optbug()Ævar Arnfjörð Bjarmason, May 21, 2022
  13. Josh SteadmonMay 27, 2022
  14. 3/5 parse-options.c: use optbug() instead of BUG() "opts" checkÆvar Arnfjörð Bjarmason, May 21, 2022
  15. Junio C HamanoMay 25, 2022
  16. 4/5 receive-pack: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, May 21, 2022
  17. Junio C HamanoMay 25, 2022
  18. Josh SteadmonMay 27, 2022
  19. Andrei RybakMay 27, 2022
  20. 5/5 cache-tree.c: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, May 21, 2022
  21. Glen ChooMay 27, 2022
  22. Josh SteadmonMay 27, 2022
  23. 0/6 usage API: add and use a bug() + BUG_if_bug()Ævar Arnfjörð Bjarmason, May 31, 2022
  24. 1/6 common-main.o: move non-trace2 exit() behavior out of trace2.cÆvar Arnfjörð Bjarmason, May 31, 2022
  25. Junio C HamanoJun 1, 2022
  26. 2/6 usage.c: add a non-fatal bug() function to go with BUG()Ævar Arnfjörð Bjarmason, May 31, 2022
  27. Glen ChooMay 31, 2022
  28. Junio C HamanoJun 1, 2022
  29. 3/6 parse-options.c: use new bug() API for optbug()Ævar Arnfjörð Bjarmason, May 31, 2022
  30. 4/6 parse-options.c: use optbug() instead of BUG() "opts" checkÆvar Arnfjörð Bjarmason, May 31, 2022
  31. Josh SteadmonMay 31, 2022
  32. Junio C HamanoJun 1, 2022
  33. 5/6 receive-pack: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, May 31, 2022
  34. 6/6 cache-tree.c: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, May 31, 2022
  35. Junio C HamanoJun 1, 2022
  36. Josh SteadmonMay 31, 2022
  37. 0/6 usage API: add and use a bug() + BUG_if_bug()Ævar Arnfjörð Bjarmason, Jun 2, 2022
  38. 1/6 common-main.o: move non-trace2 exit() behavior out of trace2.cÆvar Arnfjörð Bjarmason, Jun 2, 2022
  39. Junio C HamanoJun 3, 2022
  40. Josh SteadmonJun 7, 2022
  41. Ævar Arnfjörð BjarmasonJun 7, 2022
  42. Josh SteadmonJun 7, 2022
  43. 3/6 parse-options.c: use new bug() API for optbug()Ævar Arnfjörð Bjarmason, Jun 2, 2022
  44. 2/6 usage.c: add a non-fatal bug() function to go with BUG()Ævar Arnfjörð Bjarmason, Jun 2, 2022
  45. 5/6 receive-pack: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, Jun 2, 2022
  46. 4/6 parse-options.c: use optbug() instead of BUG() "opts" checkÆvar Arnfjörð Bjarmason, Jun 2, 2022
  47. 6/6 cache-tree.c: use bug() and BUG_if_bug()Ævar Arnfjörð Bjarmason, Jun 2, 2022
  48. Junio C HamanoJun 2, 2022
  49. Glen ChooJun 2, 2022

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.