Skip to content

Clear parse errors #4

Open
Open

Description

@Trosper3

Problem

Malformed input either throws an exception that says nothing about the input, or, worse, is silently read as something else. Tested against v0.1.2:

Silently accepted (a wrong answer with no error):

Input Read as
{1,2 {1}
{1,2}junk {1,2}jun}
{1,(2))} {1,(2),)}

Thrown, but with the wrong type or no useful message:

Case Exception
"" IndexOutOfRangeException
{(1,2},3) bare System.Exception: "Braces not matched"
an unmatched closing brace InvalidOperationException from Stack.Pop ("Stack empty")
shape mismatch InvalidOperationException: "Cannot enumerate over a value", "Cannot index into a set" (stack traces in ReduxISU/Redux#577)
failed subset constraint message literally says PLACEHOLDER: "Constraint S subset PLACEHOLDER failed because x was not a subset of PLACEHOLDER"

Wanted

  • Reject malformed input. Unbalanced braces, trailing characters and empty input are errors, never a best guess.
  • One error type. Throw a dedicated parse exception for every bad-input case, including shape mismatches and failed constraints. Never System.Exception, InvalidOperationException or IndexOutOfRangeException.
  • Say what's wrong. Include the position, what was expected and what was found, e.g. expected , or } at position 14, found x. Name the set in constraint failures instead of PLACEHOLDER.

Redux context

Activity

  1. added this to the 0.2.0 milestone on Oct 13, 2026
  2. Trosper3 commented on Oct 16, 2026

    @Trosper3
    ContributorAuthor

    A gap on the definition side, found by the coverage tests in #39: parse() accepts malformed definition strings. {N | N is set (missing brace), {N | N is set#} and {N | N is set}} are printed to the console by ANTLR's default error listener and then parsed as best it can, which is the "best guess" this issue rules out. Definition (#24) already rejects the same strings with a FormatException and the position.

    Fixing this before 0.2.0: StringParser will reject a malformed definition the same way Definition does. ConstraintGapTests.cs has the skipped test to un-skip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions