Skip to content

fix(promise): point rejection stacks at caller for promise API#4267

Open
sidorares wants to merge 4 commits intomasterfrom
more-accurate-stack-trace
Open

fix(promise): point rejection stacks at caller for promise API#4267
sidorares wants to merge 4 commits intomasterfrom
more-accurate-stack-trace

Conversation

@sidorares
Copy link
Copy Markdown
Owner

Summary

Promise rejections from mysql2/promise now attach a stack captured at the caller (e.g. connection.query()) instead of the internal wrapper line, while still rejecting the original driver error so code, errno, sql, etc. stay intact.

Implementation: Error.captureStackTrace on a lightweight holder at wrapper entry, then applyCapturedStack merges that stack onto the callback error before reject(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 Error creation to the error path.

Tests

  • test/integration/promise-wrappers/test-async-stack.test.mts updated for the new top frame.

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
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 69.81132% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.03%. Comparing base (a65c706) to head (7518393).

Files with missing lines Patch % Lines
lib/promise/connection.js 37.14% 22 Missing ⚠️
promise.js 50.00% 8 Missing ⚠️
lib/promise/pool.js 81.81% 2 Missing ⚠️
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     
Flag Coverage Δ
compression-0 90.30% <69.81%> (+0.16%) ⬆️
compression-1 91.01% <69.81%> (+0.16%) ⬆️
static-parser-0 88.76% <69.81%> (+0.16%) ⬆️
static-parser-1 89.51% <69.81%> (+0.16%) ⬆️
tls-0 90.48% <69.81%> (+0.16%) ⬆️
tls-1 90.81% <69.81%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant