fix: handle empty or undefined connections arrays without crashing#658
Open
holistis wants to merge 5 commits into
Open
fix: handle empty or undefined connections arrays without crashing#658holistis wants to merge 5 commits into
holistis wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Solvers crashed with TypeError when chips, directConnections, or netConnections were empty or undefined. - Normalize all three arrays to [] in cloneAndCorrectInputProblem (pipeline entry point) - Add ?? [] fallbacks in getConnectivityMapsFromInputProblem (defense-in-depth) - Guard ChipObstacleSpatialIndex against chips.length === 0 (Flatbush requires gt 0 items) - Type spatialIndex as Flatbush | null; guard getChipsInBounds against null index Fixes tscircuit#657
…tions
Add ?? [] to all four for-loops in MspConnectionPairSolver constructor
so the solver is safe when called directly outside the pipeline.
Add availableNetLabelOrientations ??= {} in cloneAndCorrectInputProblem
to prevent TypeError in label solvers when field is omitted.
Extend regression tests: direct MspConnectionPairSolver test and
missing availableNetLabelOrientations test (5 tests total, all pass).
…blem
Make chips, directConnections, netConnections, and availableNetLabelOrientations
optional in the InputProblem interface so callers that omit them get a compile-
time safe type, not a runtime crash.
Add ?? [] / ?? {} fallback guards in every sub-solver that iterates or indexes
these fields directly (AvailableNetOrientationSolver, NetLabelPlacementSolver,
SchematicTraceSingleLineSolver, SchematicTraceSingleLineSolver2,
visualizeInputProblem, TraceAnchoredNetLabelOverlapSolver, candidates,
GuidelinesSolver, correctPinsInsideChip, expandChipsToFitPins, and more).
Add tests/solvers/SchematicTracePipelineSolver/empty-connections.test.ts
covering empty arrays and undefined (cast as any) for both connections fields.
All 109 tests pass; bunx tsc --noEmit reports 0 errors.
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
Fixes #657. Solvers threw
TypeError: ... is not iterableorError: Unexpected numItems value: 0whenchips,directConnections, ornetConnectionswere empty orundefined.chips,directConnections, andnetConnectionsto[]incloneAndCorrectInputProblem— the single pipeline entry point, so all downstream solvers receive valid arrays?? []fallbacks ingetConnectivityMapsFromInputProblemas defense-in-depth (this function can also be called independently)ChipObstacleSpatialIndexagainstchips.length === 0— Flatbush throws when constructed with 0 items; skip index construction and return earlyspatialIndexasFlatbush | null(wasFlatbush) and guardgetChipsInBoundsagainstnullTest plan
bun test tests/repros/repro-empty-connections.test.ts— 3 new regression tests (empty arrays, undefined connections, all fields undefined)bun test tests/examples/— 50 existing example tests still passbun test tests/repros/— all existing repro tests still passbunx tsc --noEmit— no type errors