bun
bun copied to clipboard
fix: console.trace should go to stderr
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.
- [ ] Documentation or TypeScript types (it's okay to leave the rest blank in this case)
- [ ] Code changes
How did you verify your code works?
Added automated tests to validate this, also manually validated the results:
echo "console.trace('hello');" | node - >/dev/null
Trace: hello
at [stdin]:1:9
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:449:12
at [stdin]-wrapper:6:24
at runScriptInContext (node:internal/process/execution:447:60)
at evalFunction (node:internal/process/execution:87:30)
at evalScript (node:internal/process/execution:99:3)
at node:internal/main/eval_stdin:53:5
at Socket.<anonymous> (node:internal/process/execution:200:5)
at Socket.emit (node:events:530:35)
echo "console.trace('hello');" | bun - >/dev/null
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)
<!-- **For code changes, please include automated tests**. Feel free to uncomment the line below -->
<!-- I wrote automated tests -->
<!-- If JavaScript/TypeScript modules or builtins changed:
- [x] I included a test for the new code, or existing tests cover it
- [] I ran my tests locally and they pass (`bun-debug test test-file-name.test`)
-->
<!-- If Zig files changed:
- [ ] I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be
- [x] I included a test for the new code, or an existing test covers it
- [ ] JSValue used outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed
- [ ] I wrote TypeScript/JavaScript tests and they pass locally (`bun-debug test test-file-name.test`)
-->
<!-- If new methods, getters, or setters were added to a publicly exposed class:
- [ ] I added TypeScript types for the new methods, getters, or setters
-->
<!-- If dependencies in tests changed:
- [ ] I made sure that specific versions of dependencies are used instead of ranged or tagged versions
-->
<!-- If a new builtin ESM/CJS module was added:
- [ ] I updated Aliases in `module_loader.zig` to include the new module
- [ ] I added a test that imports the module
- [ ] I added a test that require() the module
-->