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

Re: [PATCH v3 3/5] config: report config parse errors using cb

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Oct 23, 2023, 18:41 UTC
Message-ID
<20231023184137.994212-1-jonathantanmy@google.com>
In-Reply-To
<a888045c04d27864edf5751ea8641fdba596779c.1695330852.git.steadmon@google.com>
Josh Steadmon <steadmon@google.com> writes:
Show 13 quoted lines
> From: Glen Choo <chooglen@google.com>
> 
> In a subsequent commit, config parsing will become its own library, and
> it's likely that the caller will want flexibility in handling errors
> (instead of being limited to the error handling we have in-tree).
> 
> Move the Git-specific error handling into a config_parser_event_fn_t
> that responds to config errors, and make git_parse_source() always
> return -1 (careful inspection shows that it was always returning -1
> already). This makes CONFIG_ERROR_SILENT obsolete since that is
> equivalent to not specifying an error event listener. Also, remove
> CONFIG_ERROR_UNSET and the config_source 'default', since all callers
> are now expected to specify the error handling they want.
I think this has to be better explained. So:
- There is already a config_parser_event_fn_t that can be configured
by a user to receive emitted config events. This callback can return
negative to halt further config parsing.
- Currently, it is git_parse_source() that detects when an error
occurs, and it emits a CONFIG_EVENT_ERROR and either dies, prints
an error, or swallows the error depending on error_action; no
matter what error_action is, it halts config parsing, as one would
expect. This commit moves the die/print/swallow handling to a
config_parser_event_fn_t that will see the CONFIG_EVENT_ERROR and die/
print/swallow.
- This new config_parser_event_fn_t does not need to swallow, since
that's the same as not passing in a callback. So it just needs to die/
print.
Show 26 quoted lines
> @@ -1039,6 +1042,29 @@ static int do_event(struct config_source *cs, enum config_event_t type,
>  	return 0;
>  }
>  
> +static int do_event_and_flush(struct config_source *cs,
> +			      enum config_event_t type,
> +			      struct parse_event_data *data)
> +{
> +	int maybe_ret;
> +
> +	if ((maybe_ret = flush_event(cs, type, data)) < 1)
> +		return maybe_ret;
> +
> +	start_event(cs, type, data);
> +
> +	if ((maybe_ret = flush_event(cs, type, data)) < 1)
> +		return maybe_ret;
> +
> +	/*
> +	 * Not actually EOF, but this indicates we don't have a valid event
> +	 * to flush next time around.
> +	 */
> +	data->previous_type = CONFIG_EVENT_EOF;
> +
> +	return 0;
> +}

A lot of this function only makes sense if the type is ERROR, so maybe rename this as flush_and_emit_error() (and don't take in a type). As it is, right now there is some confusion about how you can flush (I'm referring to the second flush) with the same type as what you passed to start_event().

Also, I don't think we should set data->previous_type here. Instead there should be a comment saying that if you're emitting ERROR, you should halt config parsing. The return value here is useless too (it signals whether we should halt config parsing, but the caller should always halt, so we don't need to return anything).

Previous: Josh SteadmonNext: Taylor Blau
Message 39 of 49 in “config-parse: create config parsing library”
  1. 0/2 config-parse: create config parsing libraryGlen Choo via GitGitGadget, Jul 20, 2023
  2. 1/2 config: return positive from git_config_parse_key()Glen Choo via GitGitGadget, Jul 20, 2023
  3. Jonathan TanJul 20, 2023
  4. Junio C HamanoJul 21, 2023
  5. Glen ChooJul 21, 2023
  6. Junio C HamanoJul 21, 2023
  7. 2/2 config-parse: split library out of config.[c|h]Glen Choo via GitGitGadget, Jul 20, 2023
  8. Jonathan TanJul 21, 2023
  9. Glen ChooJul 21, 2023
  10. 0/5 config-parse: create config parsing libraryGlen Choo, Jul 31, 2023
  11. 1/5 config: return positive from git_config_parse_key()Glen Choo, Jul 31, 2023
  12. 3/5 config: report config parse errors using cbGlen Choo, Jul 31, 2023
  13. Jonathan TanAug 4, 2023
  14. 2/5 config: split out config_parse_optionsGlen Choo, Jul 31, 2023
  15. 4/5 config.c: accept config_parse_options in git_config_from_stdinGlen Choo, Jul 31, 2023
  16. 5/5 config-parse: split library out of config.[c|h]Glen Choo, Jul 31, 2023
  17. 0/4 config-parse: create config parsing libraryJosh Steadmon, Aug 23, 2023
  18. 1/4 config: split out config_parse_optionsJosh Steadmon, Aug 23, 2023
  19. Junio C HamanoAug 23, 2023
  20. Josh SteadmonSep 21, 2023
  21. 3/4 config.c: accept config_parse_options in git_config_from_stdinJosh Steadmon, Aug 23, 2023
  22. 2/4 config: report config parse errors using cbJosh Steadmon, Aug 23, 2023
  23. Junio C HamanoAug 24, 2023
  24. Jonathan TanAug 24, 2023
  25. Junio C HamanoAug 24, 2023
  26. Josh SteadmonSep 21, 2023
  27. Junio C HamanoSep 21, 2023
  28. 4/4 config-parse: split library out of config.[c|h]Josh Steadmon, Aug 23, 2023
  29. Josh SteadmonAug 24, 2023
  30. 0/5 config-parse: create config parsing libraryJosh Steadmon, Sep 21, 2023
  31. 1/5 config: split out config_parse_optionsJosh Steadmon, Sep 21, 2023
  32. Jonathan TanOct 23, 2023
  33. Taylor BlauOct 23, 2023
  34. 5/5 config-parse: split library out of config.[c|h]Josh Steadmon, Sep 21, 2023
  35. Jonathan TanOct 23, 2023
  36. 2/5 config: split do_event() into start and flush operationsJosh Steadmon, Sep 21, 2023
  37. Jonathan TanOct 23, 2023
  38. 3/5 config: report config parse errors using cbJosh Steadmon, Sep 21, 2023
  39. Jonathan TanOct 23, 2023
  40. Taylor BlauOct 23, 2023
  41. Junio C HamanoOct 23, 2023
  42. 4/5 config.c: accept config_parse_options in git_config_from_stdinJosh Steadmon, Sep 21, 2023
  43. Jonathan TanOct 23, 2023
  44. Junio C HamanoOct 17, 2023
  45. Taylor BlauOct 23, 2023
  46. Junio C HamanoOct 23, 2023
  47. Jonathan TanOct 24, 2023
  48. Josh SteadmonOct 25, 2023
  49. Junio C HamanoOct 27, 2023

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.