Repository navigation
fix(csv-stringify): avoid invoking throwing callbacks twice #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import "should"; | ||
| import assert from "node:assert/strict"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not using assert, only should.js |
||
| import { spawnSync } from "node:child_process"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( |
||
| import { stringify } from "../lib/index.js"; | ||
|
|
||
| describe("api.callback", function () { | ||
|
|
@@ -39,6 +41,36 @@ describe("api.callback", function () { | |
| ); | ||
| }); | ||
|
|
||
| it("does not invoke a throwing callback twice", function () { | ||
| const result = spawnSync( | ||
| process.execPath, | ||
| [ | ||
| "--input-type=module", | ||
| "--eval", | ||
| ` | ||
| import assert from "node:assert/strict"; | ||
| import { stringify } from ${JSON.stringify(new URL("../lib/index.js", import.meta.url).href)}; | ||
|
|
||
| const error = new Error("Callback failed"); | ||
| let calls = 0; | ||
| let caught = false; | ||
| process.once("uncaughtException", (err) => { | ||
| assert.equal(err, error); | ||
| assert.equal(calls, 1); | ||
| caught = true; | ||
| }); | ||
| process.on("exit", () => assert.equal(caught, true)); | ||
| stringify([["value"]], () => { | ||
| calls++; | ||
| throw error; | ||
| }); | ||
| `, | ||
| ], | ||
| { encoding: "utf8" }, | ||
| ); | ||
| assert.equal(result.status, 0, result.stderr); | ||
| }); | ||
|
|
||
| it("catch error in end handler, see #386", function (next) { | ||
| const input = Array.from({ length: 200000 }).map(() => | ||
| Array.from({ length: 100 }).map( | ||
|
|
||
There was a problem hiding this comment.
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