git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] grep: improve errors for unmatched ( and )
@ 2024-03-22  8:34 Ahelenia Ziemiańska
  2024-03-22 16:41 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Ahelenia Ziemiańska @ 2024-03-22  8:34 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Josh Steadmon

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

Imagine you want to grep for (. Easy:
  $ git grep '('
  fatal: unmatched parenthesis
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 '('

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.
In this case it's also not "incomplete", it's unmatched.
But whatever.

These now 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.

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);
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] grep: improve errors for unmatched ( and )
  2024-03-22  8:34 [PATCH] grep: improve errors for unmatched ( and ) Ahelenia Ziemiańska
@ 2024-03-22 16:41 ` Junio C Hamano
  2024-03-23 13:18   ` [PATCH v2] " Ahelenia Ziemiańska
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2024-03-22 16:41 UTC (permalink / raw)
  To: Ahelenia Ziemiańska; +Cc: git, Josh Steadmon

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.

> 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.

> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] grep: improve errors for unmatched ( and )
  2024-03-22 16:41 ` Junio C Hamano
@ 2024-03-23 13:18   ` Ahelenia Ziemiańska
  2024-03-23 18:06     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Ahelenia Ziemiańska @ 2024-03-23 13:18 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Josh Steadmon

[-- Attachment #1: Type: text/plain, Size: 2845 bytes --]

Imagine you want to grep for (. Easy:

  $ git grep '('
  fatal: unmatched parenthesis

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 '('

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.
In this case it's also not "incomplete", it's unmatched.
But whatever.

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.

Link: https://bugs.debian.org/1051205
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
On Fri, Mar 22, 2024 at 09:41:40AM -0700, Junio C Hamano wrote:
> Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> writes:
> > 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.
False. -- turns all subsequent parameters into arguments, and if
there is no -e, the first argument is the pattern, and all the
subsequent ones are paths. This is normal [git] grep behaviour.

> Just keep "-e '('" in the
> description and drop the double-dash there.
Disagree. This is one of the two methodologies I've devised to work
around this in the past, and it's one of the two methodologies that
work.

All else applied.

 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);
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] grep: improve errors for unmatched ( and )
  2024-03-23 13:18   ` [PATCH v2] " Ahelenia Ziemiańska
@ 2024-03-23 18:06     ` Junio C Hamano
  2024-04-09 10:07       ` Ahelenia Ziemiańska
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2024-03-23 18:06 UTC (permalink / raw)
  To: Ahelenia Ziemiańska; +Cc: git, Josh Steadmon

Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> writes:

> Imagine you want to grep for (. Easy:
>
>   $ git grep '('
>   fatal: unmatched parenthesis
>
> 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 '('
>
> 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.
> In this case it's also not "incomplete", it's unmatched.
> But whatever.
>
> 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.
>
> Link: https://bugs.debian.org/1051205
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
> ---
> On Fri, Mar 22, 2024 at 09:41:40AM -0700, Junio C Hamano wrote:
>> Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> writes:
>> > 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.
> False. -- turns all subsequent parameters into arguments, and if
> there is no -e, the first argument is the pattern, and all the
> subsequent ones are paths. This is normal [git] grep behaviour.

Ah, thanks.  

I forgot that "git grep" was a oddball that allows revs come after
"--" in some cases.  As long as the user understands this may not
work for other commands, it is OK.  "-e" is the only officially
supported way (which is why I mentioned it in the review comments I
gave you here), so guiding users in that direction would be a better
idea anyway, though.

Thanks.

> 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);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] grep: improve errors for unmatched ( and )
  2024-03-23 18:06     ` Junio C Hamano
@ 2024-04-09 10:07       ` Ahelenia Ziemiańska
  0 siblings, 0 replies; 5+ messages in thread
From: Ahelenia Ziemiańska @ 2024-04-09 10:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Josh Steadmon

[-- Attachment #1: Type: text/plain, Size: 1947 bytes --]

Imagine you want to grep for (. Easy:

  $ git grep '('
  fatal: unmatched parenthesis

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 -e '('

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.
In this case it's also not "incomplete", it's unmatched.
But whatever.

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.

Link: https://bugs.debian.org/1051205
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
-- '(' no longer mentioned, otherwise no changes.

 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);
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-09 10:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  8:34 [PATCH] grep: improve errors for unmatched ( and ) Ahelenia Ziemiańska
2024-03-22 16:41 ` Junio C Hamano
2024-03-23 13:18   ` [PATCH v2] " Ahelenia Ziemiańska
2024-03-23 18:06     ` Junio C Hamano
2024-04-09 10:07       ` Ahelenia Ziemiańska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).