From patchwork Fri Mar 22 08:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13599742 Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 552AC38FBC for ; Fri, 22 Mar 2024 08:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.28.40.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711096492; cv=none; b=lkAWTAvfEBG+T6/FVTVc7YeEZhOmwxCqxLPwrvybMQuIibRKjjNwmnf/4zh3x7Y9BL9++oqO4sOU1n5OM9KybM1lN25FQO+cqBft3Tuw1Pvd4BTFscOCLtkZr3bgJgjMThQIVtk1vXT2tmGyGC/LCpgUIojkCB6PFsAZ0pEcNUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711096492; c=relaxed/simple; bh=cguqibnfwj+XpwPDZ8BUFshHzej5lIVDW1FC3pb69GQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=La4bkHVoNpvw3YWa29x7EYg7+Gxveb5tXLnZYDisabj9CDMZjwyeeqvZeBevN467QWh9/ods8CP7wjQEza/Sos+cTagQ/xoNI0FAai56Qah+yJwWn04N2YnOxF8zPRJ99Ou84gVT/oUOTwB5FkJXefRp+o+CZGG1+5LwmTI2FiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz; spf=pass smtp.mailfrom=nabijaczleweli.xyz; dkim=pass (2048-bit key) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b=pVh7+G+y; arc=none smtp.client-ip=139.28.40.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b="pVh7+G+y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1711096478; bh=cguqibnfwj+XpwPDZ8BUFshHzej5lIVDW1FC3pb69GQ=; h=Date:From:To:Cc:Subject:From; b=pVh7+G+yGOd7vpzjgV+KOwBbrKibjkvRRdp/Yj8pIGOpTyrCqg7xp3rDL33JE6mv4 srWiilcb+KWJ9hW44y5n/ZM+I0X9Co6oK9WaiFnd+YvrKM9WZfZmJPBcjJP+5vh7JI N/n+0Wx4eSt80cMnDVI+Ex/gtidAb3Zhl05YKOrOqinT2KodWfC75FuCF3Vbdi2Y91 WLpR4Hwg9iVrdIIO9HZhXrd+OwyVQCbVzb9t3LzdDokqQ81Wab5z7d79ZFKZXNX4mt loISMCxaNQPIYVytZzZpkKYoUsMan2p3QLZi4xGV32nF1JePkdFpqL7TSpRzHG7IfR 6gKMxaQUIMmJw== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id CAF9D165A; Fri, 22 Mar 2024 09:34:38 +0100 (CET) Date: Fri, 22 Mar 2024 09:34:38 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: git@vger.kernel.org Cc: Junio C Hamano , Josh Steadmon Subject: [PATCH] grep: improve errors for unmatched ( and ) Message-ID: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20231221-2-4202cf-dirty 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 --- 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);