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

Re: [PATCH] grep: improve errors for unmatched ( and )

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2024, 16:41 UTC
Message-ID
<xmqq34si2p8b.fsf@gitster.g>
In-Reply-To
<petpdy3bs6wpfd3ilrg6xrjsbj5y7ql4geps6y22ozdqw7vi4k@tarta.nabijaczleweli.xyz>
Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> writes:
> Imagine you want to grep for (. Easy:
Please have a blank line before and 
>   $ git grep '('
>   fatal: unmatched parenthesis

after a displayed text like this one (this applies to a few more paragraphs in the proposed log message).

> uhoh. This is plainly wrong. Unless you know specifically that
> (a) git grep has expression groups and that
> (b) the only way to work around them is by doing -- '(' or -e '('

I do not think "--" (end of options and beginning of pathspec) marker would work for that purpose, UNLESS you are talking about a file whose name is an open parenthesis. Just keep "-e '('" in the description and drop the double-dash there.

Show 5 quoted lines
> Similarly,
>   $ git grep ')'
>   fatal: incomplete pattern expression: )
> is somehow worse. ")" is a complete regular expression pattern.
> Of course, the error wants to say "group" here.
Nice problem description so far.
> These now return
Phrase it more like "Make them return" ...
>   $ ./git grep '('
>   fatal: unmatched ( for expression group
>   $ ./git grep ')'
>   fatal: incomplete pattern expression group: )
> which hopefully are clearer in indicating that it's not the expression
> that's wrong (since no pattern had been parsed at all), but rather that
> it's been misconstrued as a grouping operator.
Nicely done.
Show 28 quoted lines
> Link: https://bugs.debian.org/1051205
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
> ---
>  grep.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index 5f23d1a..ac34bfe 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -621,7 +621,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
>  		*list = p->next;
>  		x = compile_pattern_or(list);
>  		if (!*list || (*list)->token != GREP_CLOSE_PAREN)
> -			die("unmatched parenthesis");
> +			die("unmatched ( for expression group");
>  		*list = (*list)->next;
>  		return x;
>  	default:
> @@ -792,7 +792,7 @@ void compile_grep_patterns(struct grep_opt *opt)
>  	if (p)
>  		opt->pattern_expression = compile_pattern_expr(&p);
>  	if (p)
> -		die("incomplete pattern expression: %s", p->pattern);
> +		die("incomplete pattern expression group: %s", p->pattern);
>  
>  	if (opt->no_body_match && opt->pattern_expression)
>  		opt->pattern_expression = grep_not_expr(opt->pattern_expression);
Thanks.  The changes to these two messages look good.
Previous: Ahelenia ZiemiańskaNext: Ahelenia Ziemiańska
Message 2 of 5 in “grep: improve errors for unmatched ( and )”
  1. grep: improve errors for unmatched ( and )Ahelenia Ziemiańska, Mar 22, 2024
  2. Junio C HamanoMar 22, 2024
  3. grep: improve errors for unmatched ( and )Ahelenia Ziemiańska, Mar 23, 2024
  4. Junio C HamanoMar 23, 2024
  5. grep: improve errors for unmatched ( and )Ahelenia Ziemiańska, Apr 9, 2024

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.