Compare commits

...

4 Commits

Author SHA1 Message Date
Jarred Sumner
c6783c7474 Merge branch 'main' into nektro-patch-7645 2025-09-27 00:56:18 -07:00
Meghan Denny
fac2c8f95a Update inspect.test.ts 2025-09-26 19:59:19 -07:00
autofix-ci[bot]
77302a23c6 [autofix.ci] apply automated fixes 2025-09-27 01:31:12 +00:00
Meghan Denny
963e9d8409 node:stream: ensure stack traces are good 2025-09-26 18:26:57 -07:00
3 changed files with 29 additions and 9 deletions

View File

@@ -24,9 +24,6 @@ const kConstruct = Symbol("kConstruct");
function checkError(err, w, r) {
if (err) {
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
err.stack; // eslint-disable-line no-unused-expressions
if (w && !w.errored) {
w.errored = err;
}
@@ -203,9 +200,6 @@ function errorOrDestroy(stream, err, sync?) {
if ((r && (r[kState] & kAutoDestroy) !== 0) || (w && (w[kState] & kAutoDestroy) !== 0)) {
stream.destroy(err);
} else if (err) {
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
err.stack; // eslint-disable-line no-unused-expressions
if (w && (w[kState] & kErrored) === 0) {
w.errored = err;
}

View File

@@ -584,9 +584,6 @@ function onwrite(stream, er) {
state.writelen = 0;
if (er) {
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
er.stack; // eslint-disable-line no-unused-expressions
if ((state[kState] & kErrored) === 0) {
state[kErroredValue] = er;
state[kState] |= kErrored;

View File

@@ -2,11 +2,13 @@ import { Subprocess, spawn } from "bun";
import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
import fs from "fs";
import { bunEnv, bunExe, isPosix, randomPort, tempDirWithFiles } from "harness";
import * as net from "node:net";
import { join } from "node:path";
import stripAnsi from "strip-ansi";
import { WebSocket } from "ws";
import { InspectorSession, JUnitReporter, connect } from "./junit-reporter";
import { SocketFramer } from "./socket-framer";
let inspectee: Subprocess;
const anyPort = expect.stringMatching(/^\d+$/);
const anyPathname = expect.stringMatching(/^\/[a-z0-9]+$/);
@@ -526,3 +528,30 @@ test("error.stack doesnt lose frames", () => {
// We allow it to differ by the existence of <anonymous> as a string. But that's it.
expect(no.split("\n").slice(0, -2).join("\n").trim()).toBe(yes.split("\n").slice(0, -2).join("\n").trim());
});
test("node:net has nice stack trace", async () => {
const socket = new net.Socket();
const { promise, resolve, reject } = Promise.withResolvers();
socket.on("error", resolve);
socket.on("data", reject);
socket.write("hello");
const err = await promise;
let str = Bun.inspect(err);
str = str.slice(str.indexOf("^") + 1);
str = str.slice(str.indexOf("\n"));
str = str.replaceAll(import.meta.dirname, "<dir>");
str = str.replaceAll("\\", "/");
str = str.replace(/\d+/gim, "<num>");
expect(str).toMatchInlineSnapshot(`
"
error: Socket is closed
code: "ERR_SOCKET_CLOSED"
at _write (node:net:<num>:<num>)
at writeOrBuffer (internal:streams/writable:<num>:<num>)
at <anonymous> (internal:streams/writable:<num>:<num>)
at <anonymous> (<dir>/inspect.test.ts:<num>:<num>)
at <anonymous> (<dir>/inspect.test.ts:<num>:<num>)
"
`);
});