[master] 5651267d4 vrt: Harmonize regexp error messages
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Apr 14 15:47:05 UTC 2025
commit 5651267d4aa5fd9258d7385b7f6fd3e28a008d8c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Apr 9 17:19:02 2025 +0200
vrt: Harmonize regexp error messages
Better diff with the --patience option.
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index 58d980d1b..5ad281f1d 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -61,11 +61,23 @@ VPI_re_fini(vre_t *rep)
VRE_free(&vv);
}
-VCL_BOOL
-VRT_re_match(VRT_CTX, const char *s, VCL_REGEX re)
+static void
+re_fail(VRT_CTX, const char *pfx, int res)
{
struct vsb vsb[1];
char errbuf[VRE_ERROR_LEN];
+
+ assert(res < VRE_ERROR_NOMATCH);
+ AN(VSB_init(vsb, errbuf, sizeof errbuf));
+ AZ(VRE_error(vsb, res));
+ AZ(VSB_finish(vsb));
+ VSB_fini(vsb);
+ VRT_fail(ctx, "%sRegexp matching failed: %s", pfx, errbuf);
+}
+
+VCL_BOOL
+VRT_re_match(VRT_CTX, const char *s, VCL_REGEX re)
+{
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
@@ -75,13 +87,8 @@ VRT_re_match(VRT_CTX, const char *s, VCL_REGEX re)
i = VRE_match(re, s, 0, 0, &cache_param->vre_limits);
if (i >= 0)
return (1);
- if (i < VRE_ERROR_NOMATCH ) {
- AN(VSB_init(vsb, errbuf, sizeof errbuf));
- AZ(VRE_error(vsb, i));
- AZ(VSB_finish(vsb));
- VSB_fini(vsb);
- VRT_fail(ctx, "Regexp matching failed: %s", errbuf);
- }
+ if (i < VRE_ERROR_NOMATCH)
+ re_fail(ctx, "", i);
return (0);
}
@@ -106,7 +113,7 @@ VRT_regsub(VRT_CTX, int all, VCL_STRING str, VCL_REGEX re, VCL_STRING sub)
res = WS_VSB_finish(vsb, ctx->ws, NULL);
if (i < VRE_ERROR_NOMATCH)
- VRT_fail(ctx, "regsub: Regexp matching returned %d", i);
+ re_fail(ctx, "regsub: ", i);
else if (res == NULL)
VRT_fail(ctx, "regsub: Out of workspace");
else if (i > 0)
More information about the varnish-commit
mailing list