Skip to content

GraphParser: propagate parse errors as ArgumentException instead of swallowing#228

Open
wrigjl wants to merge 1 commit into
ReduxISU:CSharpAPIfrom
wrigjl:fix/graphparser-propagate-errors
Open

GraphParser: propagate parse errors as ArgumentException instead of swallowing#228
wrigjl wants to merge 1 commit into
ReduxISU:CSharpAPIfrom
wrigjl:fix/graphparser-propagate-errors

Conversation

@wrigjl
Copy link
Copy Markdown
Collaborator

@wrigjl wrigjl commented May 30, 2026

Summary

  • Five methods in GraphParser.cs were catching all exceptions and silently returning empty lists, making parse failures invisible to callers (and producing incorrect results indistinguishable from valid empty output).
  • Replaced each try/catch with explicit bounds checks that throw new ArgumentException(...) with a descriptive message and the offending parameter name, so bad input propagates as a 400 response.
  • parseNodeListWithStringFunctions had a try/catch around string operations that cannot throw — the catch was removed entirely and the method reduced to a one-liner.
  • Also clears 5 CS0168 warnings (unused catch variable e).

This really represents a poor design pattern. If there's an error, don't swallow it. Instead, figure out how to report it up the chain. Exceptions are a fine way of doing this.

Details per method

Method Old behavior New behavior
nodesGivenValidGraphAndPattern swallow, return [] check eMatches.Count == 0, throw
getNodesFromNodeListString swallow, return [] check both match collections, throw
parseNodeListWithStringFunctions swallow, return [] no try/catch needed; one-liner
parseDirectedEdgeListWithStringFunctions swallow, return [] check parts.Length < 2 per edge, throw with offending segment
parseUndirectedEdgeListWithStringFunctions swallow, return [] check currentEdge.Length < 2 per edge, throw

Test plan

  • dotnet build produces zero CS0168 warnings from GraphParser.cs
  • Valid graph inputs parse correctly (no behavior change on the happy path)
  • Invalid inputs return 400 rather than silently empty responses

🤖 Generated with Claude Code

…S0168)

Five parse methods were catching all exceptions and returning empty lists,
making parse failures invisible to callers. Replaced with explicit bounds
checks that throw ArgumentException with descriptive messages, so bad input
propagates as a 400 response rather than a silent empty result.

Also removes five CS0168 warnings (unused catch variable 'e').

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant