Skip to content

fix: propagate fatal flag across all promise wrapper error paths#4196

Open
techcodie wants to merge 1 commit intosidorares:masterfrom
techcodie:fix/promise-error-missing-fatal-in-connection-methods
Open

fix: propagate fatal flag across all promise wrapper error paths#4196
techcodie wants to merge 1 commit intosidorares:masterfrom
techcodie:fix/promise-error-missing-fatal-in-connection-methods

Conversation

@techcodie
Copy link
Copy Markdown

Problem

The promise wrapper layer had two related issues:

1. fatal flag silently dropped in 5 methods

ping(), connect(), prepare(), changeUser() in PromiseConnection and end() in PromisePool all manually copied a fixed set of error properties to localErr before rejecting:

localErr.message = err.message;
localErr.code = err.code;
localErr.errno = err.errno;
localErr.sqlState = err.sqlState;
localErr.sqlMessage = err.sqlMessage;

But err.fatal was never copied. This means promise clients calling these methods could not distinguish fatal errors (e.g. PROTOCOL_CONNECTION_LOST, ECONNREFUSED) from non-fatal ones — a silent behavioral difference from the callback API which always receives fatal.

2. Same copy block duplicated 5 times with no shared abstraction

The repetition is what caused the omission in the first place — there was no single place to add a new property.

Fix

  • Extract assignError(localErr, err) helper in make_done_cb.js that copies all error properties including fatal, and export it
  • Replace all 5 manual copy blocks in promise/connection.js and promise/pool.js with assignError()
  • makeDoneCb itself also uses assignError now for consistency
  • Also fixes PromisePool.execute falsy args check (if (args)if (args !== undefined)) to be consistent with PromisePool.query

Tests

Added test/integration/promise-wrappers/test-promise-connection-error-properties.test.mts covering ping, connect, prepare, and changeUser error propagation.

The promise wrapper layer had two related issues:

1. fatal flag was silently dropped in ping(), connect(), prepare(),
   changeUser() in PromiseConnection, and end() in PromisePool.
   These methods manually copied a fixed set of error properties
   (message, code, errno, sqlState, sqlMessage) but omitted fatal,
   meaning promise clients could not distinguish fatal errors from
   non-fatal ones — unlike callback clients which always receive it.

2. The same manual copy block was duplicated across 5 methods with
   no shared abstraction, making it easy to miss properties (as
   demonstrated by the missing fatal flag).

Fix: extract assignError() helper in make_done_cb.js that copies all
error properties including fatal, and use it in all promise wrapper
error paths. Also fixes PromisePool.execute args check (if (args) ->
if (args !== undefined)) to be consistent with PromisePool.query.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.58%. Comparing base (3adca00) to head (af1bd14).
⚠️ Report is 37 commits behind head on master.

Files with missing lines Patch % Lines
lib/promise/pool.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4196      +/-   ##
==========================================
- Coverage   90.64%   90.58%   -0.07%     
==========================================
  Files          86       86              
  Lines       14245    14233      -12     
  Branches     1798     1801       +3     
==========================================
- Hits        12913    12893      -20     
- Misses       1332     1340       +8     
Flag Coverage Δ
compression-0 90.58% <95.00%> (+0.68%) ⬆️
compression-1 ?
static-parser-0 88.11% <95.00%> (-0.23%) ⬇️
static-parser-1 88.99% <95.00%> (-0.07%) ⬇️
tls-0 89.98% <95.00%> (-0.10%) ⬇️
tls-1 90.20% <95.00%> (-0.22%) ⬇️

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.

@wellwelwel wellwelwel added the needs rebase For internal organization purpose label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase For internal organization purpose

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants