Conversation
190n
left a comment
There was a problem hiding this comment.
LGTM, let's see if the tests pass.
| test("console.trace should output to stderr", async () => { | ||
| const [out, outValue] = writable(); | ||
| const [err, errValue] = writable(); | ||
| const c = new Console({ stdout: out, stderr: err }); | ||
| c.trace("hello world!"); | ||
| out.end(); | ||
| err.end(); | ||
| expect(await outValue()).toBe(""); | ||
| expect(await errValue()).toStartWith("Trace: hello world!\n"); | ||
| }); |
There was a problem hiding this comment.
https://buildkite.com/bun/bun/builds/17607#annotation-test/js/node/console/console.test.ts
bun test v1.2.16-canary.1 (82a91eea)
✓ console.Console > global instanceof Console
✓ console.Console > new Console instanceof Console [1.99ms]
✓ console.Console > it can write to a stream [0.83ms]
✓ console.Console > can enable colors [0.94ms]
✓ console.Console > stderr and stdout are separate [0.48ms]
69 | const c = new Console({ stdout: out, stderr: err });
70 | c.trace("hello world!");
71 | out.end();
72 | err.end();
73 | expect(await outValue()).toBe("");
74 | expect(await errValue()).toStartWith("Trace: hello world!\n");
^
error: expect(received).toStartWith(expected)
Expected to start with: "Trace: hello world!\n"
Received: "Error\n at <anonymous> (/opt/homebrew/etc/buildkite-agent/builds/macOS-14-aarch64-1/bun/bun/test/js/node/console/console.test.ts:70:7)\n at <anonymous> (/opt/homebrew/etc/buildkite-agent/builds/macOS-14-aarch64-1/bun/bun/test/js/node/console/console.test.ts:66:49)\n"
at <anonymous> (/opt/homebrew/etc/buildkite-agent/builds/macOS-14-aarch64-1/bun/bun/test/js/node/console/console.test.ts:74:30)
✗ console.Console > console.trace should output to stderr [0.79ms]
✓ console._stdout [0.34ms]
✓ console._stderr [0.43ms]
7 pass
1 fail
12 expect() calls
Ran 8 tests across 1 files. [23.00ms]|
Thanks @ma-ts for the fix! I went ahead and fixed the failing Will merge once CI runs! |
|
Thanks for the PR, and sorry it sat for so long. The stderr routing is now being fixed as part of #37128, which reworks console output as a whole. This branch patches src/bun.js/ConsoleObject.zig, which no longer exists (the console now lives in src/jsc/ConsoleObject.rs), so it cannot be rebased as is. The |
What does this PR do?
This PR fixes issue #19952 by making console.trace() go to stderr. Furthermore, it improves node.js compatibility by adding the Trace: statement before the printing of the given variables.
How did you verify your code works?
Added automated tests to validate this, also manually validated the results:
echo "console.trace('hello');" | bun-debug - >/dev/null
bun-debug(43560,0x1f0475f00) malloc: nano zone abandoned due to inability to reserve vm space.
Trace: hello
at /Users/pnlmw585/dev/bun-tests/[stdin]:1:9
at loadAndEvaluateModule (7:44)
at asyncFunctionResume (9:85)
at promiseReactionJobWithoutPromiseUnwrapAsyncContext (14:20)
at promiseReactionJob (31:60)