Skip to content

Commit 41cd0c9

Browse files
committed
Includes visual snippet in validation error message
Enhances validation error messages by including the visual snippet from the lexer/parser, which provides more context to the user about the location of the error in the regular expression. This improves the debugging experience for users as they can quickly identify and fix issues in their regular expressions.
1 parent 4a5c2dc commit 41cd0c9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Regex.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ public function validate(string $regex): ValidationResult
197197

198198
return new ValidationResult(true, null, $score);
199199
} catch (LexerException|ParserException $e) {
200-
return new ValidationResult(false, $e->getMessage());
200+
$message = $e->getMessage();
201+
$snippet = $e->getVisualSnippet();
202+
203+
if ('' !== $snippet) {
204+
$message .= "\n".$snippet;
205+
}
206+
207+
return new ValidationResult(false, $message);
201208
}
202209
}
203210

0 commit comments

Comments
 (0)