Skip to content

Structured pattern errors with position tracking#79

Merged
tigerwill90 merged 11 commits into
masterfrom
feat/programatic-error-handling
Apr 12, 2026
Merged

Structured pattern errors with position tracking#79
tigerwill90 merged 11 commits into
masterfrom
feat/programatic-error-handling

Conversation

@tigerwill90
Copy link
Copy Markdown
Collaborator

@tigerwill90 tigerwill90 commented Apr 12, 2026

This PR replace sentinel errors with a new PatternError type that provides structured, programmatic error handling for invalid route patterns. Each error includes the pattern, a categorized reason, a human-readable hint, and a byte range pointing at the offending segment.

Callers can now use errors.As/errors.AsType[T] to inspect pattern errors programmatically, and PatternError.Error() renders a visual diagnostic with a cursor:

pattern: hostname: syntax: label starts with '-'
      -a.com/
      ^

pattern: path: syntax: consecutive '/'
      /foo//bar
          ^^

pattern: path: syntax: optional wildcard allowed only as suffix
      /foo/*{any}/bar
           ^^^^^^

pattern: path: regexp: error parsing regexp: invalid repeat count: `{5,2}`
      /foo/{a:a{5,2}}
              ^^^^^^

The new implementation is also a bit easier to maintain than the previous one.

@tigerwill90 tigerwill90 marked this pull request as ready for review April 12, 2026 15:37
@tigerwill90 tigerwill90 requested a review from pawndev April 12, 2026 15:37
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 99.15014% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
error.go 96.87% 1 Missing ⚠️
tree.go 85.71% 1 Missing ⚠️
txn.go 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tigerwill90 tigerwill90 merged commit 53de839 into master Apr 12, 2026
4 checks passed
@tigerwill90 tigerwill90 deleted the feat/programatic-error-handling branch April 12, 2026 16:03
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