fix: prevent matcher crash when jsonpath result is undefined#132
Open
matmar10 wants to merge 2 commits intostepci:mainfrom
Open
fix: prevent matcher crash when jsonpath result is undefined#132matmar10 wants to merge 2 commits intostepci:mainfrom
matmar10 wants to merge 2 commits intostepci:mainfrom
Conversation
When a JSONPath expression like `$.matchedCategories[*].name` evaluates against an empty array, the result is `undefined`. The `in`, `nin`, and `match` matchers called methods on `undefined` (e.g. `undefined.includes()`), throwing a TypeError. This error was caught by the catch-all block wrapping ALL jsonpath checks in http.ts, causing every jsonpath check in the step to be marked as failed with the raw body string — even checks that would have passed. Fixes: - matcher.ts: guard `in`, `nin`, and `match` against undefined/null `given` - http.ts: isolate try/catch per jsonpath key so one failure doesn't poison all other checks Co-Authored-By: Claude Opus 4.6 (1M context) <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
When a JSONPath expression evaluates to
undefined(e.g.$.items[*].nameon an empty array[]), thein,nin, andmatchmatchers throw aTypeErrorbecause they call methods like.includes()onundefined.Because the JSONPath check block in
http.tswraps ALL jsonpath checks in a singletry/catch, this one failure causes every jsonpath check in the step to be reported as failed with the raw response body as thegivenvalue — even checks that would have passed individually.Steps to Reproduce
Create a workflow with a step that checks multiple jsonpath expressions, where one resolves to
undefined:Run:
npx stepci run workflow.yamlAll three jsonpath checks fail, even though
$.json.nameand$.json.statuswould pass.Expected Behavior
$.json.namecheck → pass (value is"Widget")$.json.statuscheck → pass (value is"Done")$.json.items[*].categorycheck → fail (value isundefined, "Electronics" not found)Actual Behavior
All three checks fail with the raw response body as the
givenvalue.Root Cause
matcher.tsline 53:When
givenisundefined, throwsTypeError: Cannot read properties of undefined (reading 'includes').http.tslines 531-549: Thetry/catchwraps all jsonpath checks together, so the TypeError from one check overwrites all previously successful checks with failures.Fix
in,nin, andmatchmatchers againstundefined/nullvalues — returnfalseinstead of crashingtry/catchinside the per-key loop so one failing check doesn't poison all other checks