fix: fall back to stderr (not stdout) when log-dir is unwritable#5773
Merged
Conversation
When --log-dir points at a directory awmg cannot open log files in, the FileLogger previously fell back to os.Stdout. Because stdout is the JSON channel used by start_mcp_gateway.cjs to receive the gateway configuration, the structured log output was mixed into the JSON payload, causing: SyntaxError: Expected ',' or ']' after array element in JSON at position 5 Change handleFileLoggerError to use os.Stderr and update GetWriter() to return os.Stderr in fallback mode. Update related comments and tests.
Copilot
AI
changed the title
[WIP] Fix awmg corrupting stdout JSON channel when log-dir is unwritable
fix: fall back to stderr (not stdout) when log-dir is unwritable
May 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug where falling back to os.Stdout for logging when the log directory was unwritable would corrupt the stdout JSON channel parsed by start_mcp_gateway.cjs. The fix switches the fallback to os.Stderr across the FileLogger implementation, its GetWriter method, and updates the related doc comments and test.
Changes:
- Switch FileLogger fallback writer from
os.Stdouttoos.StderrinhandleFileLoggerErrorandGetWriter. - Update documentation comments (
common.go,file_logger.go) to reflect the new fallback target and rationale. - Update test subcase name and assertion in
file_logger_test.goto expectos.Stderr.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/file_logger.go | Switch fallback writer to stderr; update doc comments and warning string. |
| internal/logger/common.go | Update FileLogger fallback strategy doc comment to mention stderr. |
| internal/logger/file_logger_test.go | Update test subcase name and assertion to expect os.Stderr. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
This was referenced May 15, 2026
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.
When
awmgcannot open log files in--log-dir, it was falling back toos.Stdout— corrupting the stdout JSON channel thatstart_mcp_gateway.cjsparses to get the gateway config. The caller sees aSyntaxErrorwith no actionable error fromawmg, since log lines like[2026-...] [INFO] [startup]are valid-looking JSON array starts.Changes
internal/logger/file_logger.go—handleFileLoggerError:os.Stdout→os.Stderr;GetWriter()fallback return:os.Stdout→os.Stderr; fallback warning message updated accordinglyinternal/logger/common.go— Update doc comment describing the FileLogger fallback strategyinternal/logger/file_logger_test.go— Update test subcase and assertion to expectos.Stderr