Skip to content

fix(csv-stringify): avoid invoking throwing callbacks twice - #526

Open
20ns wants to merge 1 commit into
adaltas:masterfrom
20ns:fix/stringify-callback-exceptions
Open

20ns wants to merge 1 commit into
adaltas:masterfrom
20ns:fix/stringify-callback-exceptions

Conversation

@20ns

@20ns 20ns commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

When a successful stringify callback throws, the end handler catches the caller's exception and invokes that callback again with the error.

Limit the catch to collecting the output, then invoke the callback outside it. Oversized-output errors retain their existing callback handling.

Add one subprocess regression checking that the callback runs once and its original exception escapes. It fails before the fix and passes afterward.

Validation on Node.js 22.22.0:

  • Focused regression: passes, and fails against the original source with 2 !== 1 callback invocations.
  • csv-stringify test suite and TypeScript checks: 233 passing, 1 existing pending test.
  • Full workspace test command: all 14 projects pass.
  • Changed-file ESLint and Prettier checks: pass.
  • csv-stringify build: passes.
  • git diff --check: passes.

let data;
try {
callback(undefined, chunks.join(""));
data = chunks.join("");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data = chunks.join(""); will never throw an error, try/catch is not used

@@ -1,4 +1,6 @@
import "should";
import assert from "node:assert/strict";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using assert, only should.js

@@ -1,4 +1,6 @@
import "should";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that spaning a new process is necessary to illustrate this issue.

@@ -1,4 +1,6 @@
import "should";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that spaning a new process is necessary to illustrate this issue.

Also, using a sync api (spawnSync here) is not appropriate.

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.

2 participants