-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some regex errors are misleading and could be improved #39075
Comments
Thanks for the report, but what version are you running / testing this on? With the current code, for example, |
Oh, I ran them under newest VS inside FSI window. I think that uses 4.8. I should've tested these with Core as well, I guess. But, @stephentoub, you're showing the same error I did ;), except for the window dressing, which apparently got updated. |
Yes :-)
The core of the text is the same for these examples. But there's additional description around it, such as the position, to help clarify. |
@stephentoub, to prevent further confusion, I've updated the text above with the errors from both Framework and Core. |
Cool, thanks :-) |
Description
Going over the possible exceptions for regexes (#38872) I noticed that a few appear to be raised that could be improved upon.
Better to raise MalformedNameRef
Both the above would be clearer if they raised
MalformedNameRef
.\k<...>
is a valid way to reference a group, soMalformedNameRef
just seems more logical.Also, the 2nd case above, the text says "must begin with a word character", which is precisely what already happens in the regex...
Also, the Core version says
\\k
is not a recognized escape sequence, but there's no\\k
in the expression (which would be valid), only\k
.Text is too specific or wrong
Not an
{x, y}
quantifier here:Not a capture group in this expression:
Confusing error, but not wrong
But I would find
UnterminatedBracket
clearer here, as non-termination of brackets or parens should be high-prio errors before the more special errors.Unclear text when alternation is malformed
I think this can be improved by making this error "conditional alternation malformed". Also, printing "(?(3) )" doesn't help here, as it is no present like that in the original expression.
But given the expression, I'd rather expect it to raise
TooFewParentheses
.More info
Considering that Regex has been given so much attention lately (thanks so much for the perf improvements!!!), I figured why not also give the errors some scrutiny ;).
Edited: added full exception messages for both .NET Core and .NET Framework following up on #39075 (comment). The specific part is, as can be seen, the same for either environment.
Tested with:
The text was updated successfully, but these errors were encountered: