Skip to content

fix(regex): a declined construct in a runtime pattern is catchable - #142

Merged
BuddhiLW merged 8 commits into
stagingfrom
fix/regex-runtime-unsupported-catchable
Dec 1, 2026
Merged

BuddhiLW merged 8 commits into
stagingfrom
fix/regex-runtime-unsupported-catchable

Conversation

@BuddhiLW

@BuddhiLW BuddhiLW commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Fixes #136. Amends accepted divergence AD-060, by the maintainer's decision of 2026-12-01.

The defect

A pattern that uses a construct cljw declines (a backreference, an unsupported inline flag or class form) raised the uncatchable feature_not_supported error from every surface. re-pattern on one bad string ended the process, even inside (try ... (catch Throwable ...)):

(try (re-pattern "(a)\\1") (catch Throwable _ :caught))   ; process ends

A server that takes patterns from clients could not refuse one. ADR-0031 names linear-time matching as what lets untrusted patterns run; an untrusted pattern that ends the host defeats that.

The decision

  • A pattern built from a runtime string is data. It raises the new catalog code regex_construct_not_supported, kind value_error: a catchable IllegalArgumentException whose message still names the construct. This covers re-pattern, Pattern/compile and the String regex methods; all go through regex_value.raiseCompileError.
  • A #"..." literal is code. The analyzer calls the new raiseLiteralCompileError, which keeps the uncatchable signal for a declined construct.

src/runtime/error/catalog.zig already made the same move for malformed JSON, EDN and the STM ops.

What moved with it

  • .dev/accepted_divergences.yaml: the AD-060 summary, example and pin state the split; its check expression uses the literal.
  • test/e2e/regex_parity_gaps.sh: the uncatchable pin uses the literal #"(a)\1".
  • test/clj/suites/regex_test.clj: the runtime half, through re-pattern, Pattern/compile and String.split, plus a check that the process goes on.

Checks

Built with zig build -Dwasm -Doptimize=ReleaseSafe (Zig 0.16.0):

  • test/clj/run_suites.clj: 171 suites loaded, 1001 tests, 5399 assertions, 0 failures, 0 errors
  • test/e2e/regex_parity_gaps.sh: 3 of 3
  • scripts/check_accepted_divergences.sh: ok, 68 divergences, 60 executable
  • scripts/corpus_regression.clj: 5515 of 5515 golden outputs reproduced
  • zig build test and zig fmt --check pass

The full gate (test/run_all.sh) was not run locally.

Not done

The release-wave coordinator asked for a devil's-advocate review and an ADR number for a change to a pinned divergence. The maintainer decided directly, so there is no new ADR file; the amendment is recorded in the AD-060 entry itself. Add an ADR if the project wants one.

Please do not merge before release PR #138 lands. This PR, #139 and #141 each add a line under Unreleased in CHANGELOG.md, so the second and third to merge need a small conflict resolved there.

`(require 'no.such.ns)` raised lib_not_found as a name error, which is a
RuntimeException. The JVM raises java.io.FileNotFoundException, and
portable code relies on that to detect an optional namespace:

    (try (require 'x) (catch java.io.FileNotFoundException _ ...))

lib_not_found now has kind file_not_found, so that catch matches, and
IOException and Exception still do through the supertype chain. The
message is unchanged; the uncaught report is headed "File not found".

`alias` and `refer` raised the same code for a namespace that is not
loaded, although they look for no file. They now raise namespace_unknown
("No namespace"), as on the JVM.

narrowCallFnError passes FileNotFound through, so a `require` or `slurp`
that fails while a macro expands stays catchable instead of becoming an
internal error.

Refs #137
A pattern that uses a construct cljw declines (a backreference, an
unsupported inline flag or class form) raised the uncatchable
feature_not_supported error from every surface, so `re-pattern` on one bad
string ended the process even inside (try ... (catch Throwable ...)). A
server that takes patterns from clients could not refuse one.

A pattern built from a runtime string is data. It now raises the new
catalog code regex_construct_not_supported, kind value_error: a catchable
IllegalArgumentException whose message still names the construct. This
covers re-pattern, Pattern/compile and the String regex methods, which all
go through regex_value.raiseCompileError.

A #"..." literal is code. The analyzer calls the new
raiseLiteralCompileError, which keeps the uncatchable signal for a
declined construct.

This amends accepted divergence AD-060, by the maintainer's decision of
2026-12-01. Its entry, its check expression and its pin in
test/e2e/regex_parity_gaps.sh now use the literal; the runtime half is
pinned in test/clj/suites/regex_test.clj.

Fixes #136
The require of a missing namespace raises a file_not_found error, so
the rendered report label changed from "Name error" to "File not found".
@BuddhiLW
BuddhiLW merged commit 27a0359 into staging Dec 1, 2026
5 of 7 checks passed
@BuddhiLW
BuddhiLW deleted the fix/regex-runtime-unsupported-catchable branch December 1, 2026 18:58
BuddhiLW added a commit that referenced this pull request Dec 1, 2026
No textual conflicts. build.zig.zon takes staging's version 1.15.9 and
keeps this branch's minimum_zig_version, zlinter and zwasm pins.
CHANGELOG keeps staging's [1.15.9] section unchanged and its Unreleased
entries; the auto-merge had folded this branch's four Zig 0.17.1 /
zwasm v2.12.1 entries into [1.15.9], so they are moved back under
Unreleased, since they did not ship in 1.15.9.

The incoming regex (#139, #142) and require (#141) code uses no API
0.17.1 removed or deprecated, so it builds unchanged: the 0.17 rename
pass over src touches nothing, `zig fmt --check` is clean, and the
-Dwasm ReleaseSafe build is green. All 171 clj suites pass (1006 tests,
5420 assertions).

Smell-audited: 0: merge only; build.zig.zon takes staging's version, no Zig source changed by the resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant