fix(promise): point rejection stacks at caller for promise API#4267
Open
fix(promise): point rejection stacks at caller for promise API#4267
Conversation
Capture stack at wrapper entry with Error.captureStackTrace on a holder object, apply the stack string to callback errors via applyCapturedStack, and reject the original driver error so MySQL fields are preserved. Update async stack integration tests for the caller as the top frame. Related to #4265
CI and different Node versions can reorder frames (e.g. processTicksAndRejections) or shift line numbers; stack[0] is not always the await line. Match any parsed frame whose file is this test module.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4267 +/- ##
==========================================
+ Coverage 90.87% 91.03% +0.16%
==========================================
Files 89 90 +1
Lines 14501 14520 +19
Branches 1864 1868 +4
==========================================
+ Hits 13178 13219 +41
+ Misses 1323 1301 -22
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Promise rejections from
mysql2/promisenow attach a stack captured at the caller (e.g.connection.query()) instead of the internal wrapper line, while still rejecting the original driver error socode,errno,sql, etc. stay intact.Implementation:
Error.captureStackTraceon a lightweight holder at wrapper entry, thenapplyCapturedStackmerges that stack onto the callback error beforereject(err).Related
Follow-up to the discussion in #4265 (revert of #4257): stack UX and tests were intentionally split from the revert; this PR adds the caller-accurate framing without deferring
Errorcreation to the error path.Tests
test/integration/promise-wrappers/test-async-stack.test.mtsupdated for the new top frame.