Repository navigation
bun-lambda: print a console string as it is and every other value with Bun.inspect #35441
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
Open
robobun
wants to merge
2
commits into
main
Choose a base branch
from
farm/cee5b67a/bun-lambda-console-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+341
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🟡 (optional) Lambda handlers that log a Buffer, URL or URLSearchParams with %s get the inspected structure in CloudWatch, where Node's runtime prints the text. hasBuiltInToString at packages/bun-lambda/runtime.ts:52 treats any constructor found on globalThis as built-in. Node's rule covers only ECMAScript intrinsics (the list at src/js/internal/util/inspect.js:203), so console.log("GET %s", url) prints the multi-line URL struct instead of the href and a Buffer prints its byte list. Fix: classify by Node's fixed intrinsic-name set rather than globalThis identity, so Buffer, URL, URLSearchParams and their subclasses go through String(value) while Error, Date and plain objects still inspect.
Why this was flagged
A handler calls console.log("fetching %s", new URL(request.url)) or console.log("body: %s", Buffer.from(text)); console.log is overridden at packages/bun-lambda/runtime.ts:148 and the %s arm at runtime.ts:87 calls hasBuiltInToString. The walk stops at URL.prototype, which owns toString, reads its constructor, and runtime.ts:52 finds globalThis.URL === URL, so it returns true and the value goes to Bun.inspect, the 14-line struct shown at test/js/web/url/url.test.ts:256, folded with \r into one record; a Buffer prints as its numeric byte list. Node's util.format and Bun's port at src/js/internal/util/inspect.js:2556-2558 test the constructor name against a fixed intrinsic set (inspect.js:203) that has no Buffer, URL or URLSearchParams, so they print String(value). The base branch inspected every argument, so output is not worse than base, but the comment at runtime.ts:30 and the PR state this is node:util's rule.
Verification: Triggered whenever a handler logs a URL, URLSearchParams or Buffer under %s. packages/bun-lambda/runtime.ts:52 decides "built-in" by
(globalThis as any)[constructor.name] === constructor, so the %s arm at runtime.ts:87-88 calls Bun.inspect(value). Node's rule at src/js/internal/util/inspect.js:2556-2559 checksbuiltInObjects.has(descriptor.value.name), where URL/Buffer/URLSearchParams are absent.