Skip to content
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

Weird 'token recognition error' error messages on stdout/stderr when evaluation fails #118

Open
bitbonk opened this issue Aug 20, 2024 · 3 comments

Comments

@bitbonk
Copy link

bitbonk commented Aug 20, 2024

We have updgraded CoreCLR-NCalc from version 3.1.251 to 3.1.253. Now when an evaluation fails with an exception (as expected) there is also always some "weird" output on stdout (or stderr?) like this:

line 1:5 token recognition error at: '$'
line 1:8 token recognition error at: '@'
line 1:9 token recognition error at: '#*%'

This can be reproduced by running the following xunit test on the console using dotnet test

using FluentAssertions;
using NCalc;

namespace NCalcErrors;

public class UnitTest1
{
    [Theory]
    // ...
    [InlineData("+= x%$*%@#*%")]
    public void Evaluate_InvalidExpression_Throws(string expression)
    {
        var sut = new Expression(
            expression,
            EvaluateOptions.IgnoreCase |
            EvaluateOptions.MatchStringsWithIgnoreCase |
            EvaluateOptions.UseDoubleForAbsFunction);

        sut.Invoking(s => s.Evaluate()).Should().Throw<Exception>();
    }
}
@bitbonk
Copy link
Author

bitbonk commented Aug 20, 2024

Just discovered that behavior also existed in CoreCLR-NCalc version 3.1.251. It just that the upgrade from of the .NET SDK from version 8.0.302 to 8.0.400 made this visible. Running the above test with CoreCLR-NCalc version 3.1.251 and .NET SDK 8.0.302 does not result in the output but running the above test with CoreCLR-NCalc version 3.1.251 and .NET DSK 8.0.400 suddenly does.

@david-brink-talogy
Copy link
Collaborator

The output is coming from the default error listener in ANTLR4.
https://github.com/antlr/antlr4/blob/811b7fda58bd14d7f0abc496b6fd651dfa01ed97/runtime/CSharp/src/Lexer.cs#L559.

@bitbonk
Copy link
Author

bitbonk commented Aug 20, 2024

@david-brink-talogy Yes, it looks like the default error listener ConsoleErrorListener.Instance must be removed using RemoveErrorListener()

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

No branches or pull requests

2 participants