This makes it more likely that you can actually debug something like
"sed: bad regex: empty (sub)expression" or
"sed: bad regex: parentheses not balanced" from a build failure log,
where you don't necessarily know where the failure came from.

This also seems like it might be useful generally, although GNU grep
doesn't include this detail in its error messages, and busybox doesn't
even seem to notice that regcomp() failed?

(Realistically if the Android build team wants to move forward with "one
true regex implementation", we're going to have to add some GNU-isms to
the Android regex implementation. But we'd need to find them first! Note
that the two examples given above are real examples from failed buildbot
builds, but they occur early in the respective builds so there are
likely many more to look at after these. Interestingly, the first of the
two appears to be the more general case of something disallowed by POSIX
that xregcomp() already has a workaround for.)
---
 lib/xwrap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
From 07376d8b78ae63b777d4f9ce01eb15f8136b8746 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Fri, 6 Nov 2020 10:25:37 -0800
Subject: [PATCH] xregcomp: add the specific regex we couldn't parse to the
 error message.

This makes it more likely that you can actually debug something like
"sed: bad regex: empty (sub)expression" or
"sed: bad regex: parentheses not balanced" from a build failure log,
where you don't necessarily know where the failure came from.

This also seems like it might be useful generally, although GNU grep
doesn't include this detail in its error messages, and busybox doesn't
even seem to notice that regcomp() failed?

(Realistically if the Android build team wants to move forward with "one
true regex implementation", we're going to have to add some GNU-isms to
the Android regex implementation. But we'd need to find them first! Note
that the two examples given above are real examples from failed buildbot
builds, but they occur early in the respective builds so there are
likely many more to look at after these. Interestingly, the first of the
two appears to be the more general case of something disallowed by POSIX
that xregcomp() already has a workaround for.)
---
 lib/xwrap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/xwrap.c b/lib/xwrap.c
index e75fa811..26fcb8df 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -938,7 +938,7 @@ void xregcomp(regex_t *preg, char *regex, int cflags)
 
   if ((rc = regcomp(preg, regex, cflags))) {
     regerror(rc, preg, libbuf, sizeof(libbuf));
-    error_exit("bad regex: %s", libbuf);
+    error_exit("bad regex '%s': %s", regex, libbuf);
   }
 }
 
-- 
2.29.1.341.ge80a0c044ae-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to