Skip to content

fix(format): reject promises on formatter errors - #1317

Open
yuxino wants to merge 1 commit into
C2FO:mainfrom
yuxino:fix/format-promise-errors
Open

yuxino wants to merge 1 commit into
C2FO:mainfrom
yuxino:fix/format-promise-errors

Conversation

@yuxino

@yuxino yuxino commented Nov 12, 2026

Copy link
Copy Markdown

A formatting transform that throws or calls back with an error can terminate the Node process when using writeToBuffer() or writeToString(), even with a Promise rejection handler:

const { writeToString } = require('@fast-csv/format');

writeToString([{ age: -1 }], {
    transform(row) {
        if (row.age < 0) throw new Error('Age must not be negative');
        return row;
    },
}).catch(console.error);

The formatter stream's error now rejects the returned Promise. Tests cover both wrappers with synchronous transforms, asynchronous transforms, and an error while writing headers for empty input. Normal output is unchanged.

Verified the full test suite on Node 22 and 24, plus build, lint, formatting, examples, and benchmarks.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@c2fo-cibot c2fo-cibot Bot added the size/M Denotes a PR that changes 30-99 lines label Nov 12, 2026

This branch has not been deployed

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

Labels

size/M Denotes a PR that changes 30-99 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant