Problem
All regex-based assertions compile user-supplied patterns with regexp.MustCompile, so any invalid pattern panics instead of producing a clean error.
Reproduction
$ http-assert --assert-body '[unclosed' http://127.0.0.1:8791/ok
panic: regexp: Compile(`[unclosed`): error parsing regexp: missing closing ]: `[unclosed`
goroutine 1 [running]:
regexp.MustCompile({0x16f0022d0, 0x9})
/opt/homebrew/Cellar/go/1.26.5/libexec/src/regexp/regexp.go:313 +0xb0
main.AssertBodyMatch({0x16f0022d0, 0x9})
/…/assertions.go:125 +0x24
main.parseAssertionFlags(0x91639da4008)
/…/main.go:236 +0x620
…
[exit=2]
Same for --assert-header 'X: (bad' (assertions.go:81) and --assert-redirect.
Why it matters
Assertion patterns require heavy shell escaping, so typos are routine. In CI this surfaces as a raw Go crash with exit code 2, which is not a documented exit code (see the exit-code issue).
Affected code
assertions.go:81 — AssertHeaderMatch
assertions.go:125 — AssertBodyMatch
AssertRedirectMatch
- called from
main.go:221,236,264
Suggested fix
Compile patterns during flag parsing, return an error instead of panicking, and exit with the invalid-arguments code, e.g.:
Error: Invalid value for --assert-body flag: error parsing regexp: missing closing ]: `[unclosed`
Problem
All regex-based assertions compile user-supplied patterns with
regexp.MustCompile, so any invalid pattern panics instead of producing a clean error.Reproduction
Same for
--assert-header 'X: (bad'(assertions.go:81) and--assert-redirect.Why it matters
Assertion patterns require heavy shell escaping, so typos are routine. In CI this surfaces as a raw Go crash with exit code 2, which is not a documented exit code (see the exit-code issue).
Affected code
assertions.go:81—AssertHeaderMatchassertions.go:125—AssertBodyMatchAssertRedirectMatchmain.go:221,236,264Suggested fix
Compile patterns during flag parsing, return an error instead of panicking, and exit with the invalid-arguments code, e.g.: