fix(logger): use console API in JSON logger for cross-runtime compatibility#17332
Open
astrobot-houston wants to merge 2 commits into
Open
fix(logger): use console API in JSON logger for cross-runtime compatibility#17332astrobot-houston wants to merge 2 commits into
console API in JSON logger for cross-runtime compatibility#17332astrobot-houston wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 8e1ea25 The changes in this PR will be included in the next version bump. This PR includes changesets to release 396 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
@matthewp this genuinely appears to be a flake. Can you rebase main? If it fails again, I’ll peel the onion. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a crash where
astro dev --json(or any project using the JSON logger) would return HTTP 500 for every request when using the Cloudflare adapter.Closes #17280
Root Cause
The JSON logger's
write()method referencedprocess.stderrandprocess.stdoutdirectly. When the Cloudflare adapter handles requests inside workerd — Cloudflare's local dev runtime — theprocessglobal doesn't exist, causing aReferenceErroron every log call. The error then cascaded: the error handler tried to log via the same broken logger, swallowing the original message and returning a 500.This is especially easy to hit without explicitly passing
--json, because Astro automatically enables JSON logging when it detects it is running inside a coding agent.Fix
packages/astro/src/core/logger/impls/json.tsnow usesconsole.error/console.loginstead ofprocess.stderr.write/process.stdout.write. The console API is available in all JS runtimes including workerd. This matches the pattern already used by the sibling console logger.The node logger (
node.ts) was intentionally not changed — it only ever runs in Node.js whereprocessis guaranteed, and it relies onprocess.stdout.writeto supportnewLine: falsefor composing multi-part build output lines (e.g. filename + render timing on the same line). Changing it would break that formatting.As a side effect, the JSON logger no longer emits a partial (non-newline-terminated) write for
newLine: falseevents, which previously concatenated two JSON objects without a separator — producing unparseable output. Each event now unconditionally gets its own line, which is correct JSONL format.Changes
packages/astro/src/core/logger/impls/json.ts— replaceprocess.stdout/process.stderrwithconsole.log/console.error; remove now-unusedConsoleStreamtype andnode:streamimportpackages/astro/test/units/logger/destination.test.ts— update tests to spy onconsole.log/console.errorinstead ofprocess.stdout.write/process.stderr.write; add a cross-runtime compatibility test assertingwrite()contains noprocess.reference.changeset/cool-rice-exist.md— patch changeset forastro