GraphParser: propagate parse errors as ArgumentException instead of swallowing#228
Open
wrigjl wants to merge 1 commit into
Open
GraphParser: propagate parse errors as ArgumentException instead of swallowing#228wrigjl wants to merge 1 commit into
wrigjl wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GraphParser.cswere catching all exceptions and silently returning empty lists, making parse failures invisible to callers (and producing incorrect results indistinguishable from valid empty output).try/catchwith explicit bounds checks thatthrow new ArgumentException(...)with a descriptive message and the offending parameter name, so bad input propagates as a 400 response.parseNodeListWithStringFunctionshad atry/catcharound string operations that cannot throw — the catch was removed entirely and the method reduced to a one-liner.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
nodesGivenValidGraphAndPattern[]eMatches.Count == 0, throwgetNodesFromNodeListString[]parseNodeListWithStringFunctions[]parseDirectedEdgeListWithStringFunctions[]parts.Length < 2per edge, throw with offending segmentparseUndirectedEdgeListWithStringFunctions[]currentEdge.Length < 2per edge, throwTest plan
dotnet buildproduces zero CS0168 warnings fromGraphParser.cs🤖 Generated with Claude Code