fix: prevent TypeError in batch with output parameters when sql errors#1864
Merged
Merged
Conversation
When a batch with declared output parameters fails before the appended `select 1 as [___return___], ...` trailer can run (e.g. a compile error or a runtime error under SET XACT_ABORT ON), `recordsets` is empty and `recordsets.pop()[0]` throws synchronously inside the tedious request callback, preventing the user callback from being invoked and leaving the request promise unsettled. Guard the access with optional chaining so the SQL error propagates through the existing callback path and rejects the promise normally. Fixes tediousjs#1863 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0e108f5 to
0db36a4
Compare
|
🎉 This PR is included in version 12.5.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
recordsets.pop()[0]inlib/tedious/request.jswith optional chaining so a SQL error in a batch with declared output parameters doesn't crash before the request callback fires.select 1 as [___return___], ...trailer can run (e.g. a compile error, or a runtime error underSET XACT_ABORT ON),recordsetsis empty,recordsets.pop()isundefined, and[0]throws synchronously inside the tedious request callback. The user callback never fires, the request promise never settles, and the connection is never released.'batch with output parameters and sql error') that reproduces the original crash and asserts the SQL error rejects the promise as aRequestError/EREQUEST.Test plan
npm run test-tedious -- --grep 'batch with output parameters and sql error'passes (was crashing withTypeError: Cannot read properties of undefined (reading '0') at request.js:480on master)npm run lintcleanFixes #1863
🤖 Generated with Claude Code