question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ArgumentNullException` thrown on parse failure instead of helpful message

See original GitHub issue

Hi there,

I’ve just added some extra unit tests to my parsing code (following on from https://github.com/b3b00/csly/issues/254), and I’m seeing an ArgumentNullException thrown from inside the parser in one particular test case.

I’m using csly 2.8.0.

I’ve produced a simplified version of my app (with no extra dependencies this time!) which shows a failing test: https://github.com/RoystonS/CslyNullIssue

It’s the same parser as in my real app, but instead of generating an AST I’ve made this one simply generate a string during parsing to make reproduction easier.

The test output for the failing test is:

Message: 
System.ArgumentNullException : Value cannot be null. (Parameter 'collection')

Stack Trace: 
List`1.InsertRange(Int32 index, IEnumerable`1 collection)
List`1.AddRange(IEnumerable`1 collection)
SyntaxParseResult`1.AddExpectings(IEnumerable`1 expected)
EBNFRecursiveDescentSyntaxParser`2.ParseExpressionRule(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
EBNFRecursiveDescentSyntaxParser`2.Parse(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
RecursiveDescentSyntaxParser`2.ParseNonTerminal(IList`1 tokens, String nonTerminalName, Int32 currentPosition)
EBNFRecursiveDescentSyntaxParser`2.Parse(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
RecursiveDescentSyntaxParser`2.ParseNonTerminal(IList`1 tokens, String nonTerminalName, Int32 currentPosition)
RecursiveDescentSyntaxParser`2.ParseNonTerminal(IList`1 tokens, NonTerminalClause`1 nonTermClause, Int32 currentPosition)
EBNFRecursiveDescentSyntaxParser`2.ParseExpressionRule(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
<34 more frames...>
RecursiveDescentSyntaxParser`2.ParseNonTerminal(IList`1 tokens, NonTerminalClause`1 nonTermClause, Int32 currentPosition)
EBNFRecursiveDescentSyntaxParser`2.ParseExpressionRule(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
EBNFRecursiveDescentSyntaxParser`2.Parse(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
RecursiveDescentSyntaxParser`2.ParseNonTerminal(IList`1 tokens, String nonTerminalName, Int32 currentPosition)
EBNFRecursiveDescentSyntaxParser`2.Parse(IList`1 tokens, Rule`1 rule, Int32 position, String nonTerminalName)
RecursiveDescentSyntaxParser`2.Parse(IList`1 tokens, String startingNonTerminal)
Parser`2.ParseWithContext(IList`1 tokens, Object parsingContext, String startingNonTerminal)
Parser`2.Parse(String source, String startingNonTerminal)
ExpressionParser.Parse[T](String expression) line 94
UnitTest1.BooleanParser(String expression, String expected) line 52

This particular test is a fairly heavily nested expression

1 < 2 && 1 <= 2 && 1 == 2 && 1 >= 2 && 1 > 2 && 1 != 2 && 1 <> 2 This test case is checking grouping behaviour and also doing exhaustive testing of all my operators. The expected parse result should be (((((((1 < 2) AND (1 <= 2)) AND (1 == 2)) AND (1 >= 2)) AND (1 > 2)) AND (1 != 2)) AND (1 != 2)) but the parse is throwing ArgumentNullException.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
b3b00commented, Dec 1, 2021

I 've release nuget 2.8.0.1

0reactions
b3b00commented, Nov 30, 2021

I’ve pushed one more fix that help deliver better error message :

unexpected "COMPARISON [>] @line 1, column 72" (COMPARISON). Expecting MINUS, OFF, ON, HEX_NUMBER, DECIMAL_NUMBER, LVAR, SIMVAR, LPAREN, .

You can test it on the same branch as previously

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle the ArgumentNullException in C# | Rollbar
The ArgumentNullException occurs in C# when null arguments are passed to a method in that expects non-null values.
Read more >
c# - Throwing ArgumentNullException
My only issue with that code would be the error message in the ArgumentNullException not actually specifying which argument was null. – Søren ......
Read more >
Throwing Standard Exception Types in .NET
Application code must differentiate between exceptions caused by null/non-null arguments. This post shows you how to raise such exceptions.
Read more >
ArgumentException Class (System)
ArgumentException is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of...
Read more >
Throw and Re-throw Exceptions in C# | Pluralsight
When a situation occurs that violates a system or application constraint, it can generate an exception to signal to the caller that an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found