Skip to content

Add ParsePattern and ParsePathPattern to report why a pattern is invalid - #122

Open
loderunner wants to merge 1 commit into
bmatcuk:masterfrom
TryColibri:master
Open

loderunner wants to merge 1 commit into
bmatcuk:masterfrom
TryColibri:master

Conversation

@loderunner

Copy link
Copy Markdown

Today ValidatePattern returns a bool and Match/Glob return a bare ErrBadPattern, with no details of what went wrong, leaving the user guessing how to fix it.

This adds ParsePattern and ParsePathPattern, which return an error with the reason and byte offset:

err := doublestar.ParsePattern("ab{c,d}[")
// syntax error in pattern: unclosed character class starting at offset 7
errors.Is(err, doublestar.ErrBadPattern) // true

Backwards compatibility

  • ValidatePattern/ValidatePathPattern keep their bool signatures
  • Match/PathMatch/Glob still return the plain ErrBadPattern

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