fix(scripts): pin stderr to UTF-8 in the config scripts - #2795
fix(scripts): pin stderr to UTF-8 in the config scripts#2795aranellaeth wants to merge 2 commits into
Conversation
The three scripts under src/scripts write diagnostics that quote user-controlled text: the config path, tomllib's parse message, and memlog's --field pair. Only stdout was pinned, so on a Windows console (cp1252) that text comes back as escapes while the user is trying to read which file to go fix. Generalizes the pin_utf8 helper merged for brain.py in bmad-code-org#2578 to resolve_config, resolve_customization and memlog. errors= is passed through so stderr's POSIX backslashreplace default is not silently downgraded to strict. Adds a subprocess test driving resolve_customization under PYTHONIOENCODING=cp1252 against a project path containing Turkish characters. It fails without the stderr pin and passes with it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe scripts now pin console streams to UTF-8 while preserving existing error handlers. A regression test verifies that malformed configuration diagnostics with non-ASCII paths remain readable under cp1252 console settings. ChangesConsole encoding handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The scripts now emit readable UTF-8 diagnostics while preserving existing error handling, improving troubleshooting for paths containing non-ASCII characters. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryPins the configuration scripts’ console streams to UTF-8 while preserving each stream’s existing error handler.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/scripts/memlog.py | Adds UTF-8 pinning for stdout and stderr before dispatching memlog subcommands. |
| src/scripts/resolve_config.py | Refactors stdout encoding through pin_utf8 and pins diagnostic output to UTF-8. |
| src/scripts/resolve_customization.py | Applies the shared UTF-8 stream behavior to resolved customization output and errors. |
| src/scripts/tests/test_resolve_customization.py | Verifies that parse errors preserve readable non-ASCII paths when the inherited I/O encoding is cp1252. |
Reviews (2): Last reviewed commit: "docs(scripts): restore and extend docstr..." | Re-trigger Greptile
… touches The first commit folded write_json_stdout's body into pin_utf8 and dropped its existing docstring in resolve_config.py along with it. That was unintended; restored, and its sibling in resolve_customization.py now has the same. Also documents main() in the three scripts and the two test entities this PR touches, taking docstring coverage over the touched set from 4/13 to 11/13.
|
Pushed The first commit folded That was unintended. It is restored, and its sibling in Docstring coverage over the touched set goes from 4/13 to 11/13 (84.6%). The follow-up is +8/-0, pure additions. The two test methods that remain undocumented predate this PR and I did not touch their bodies, so I left them alone rather than widening the diff. |
Problem
The three scripts under
src/scriptswrite diagnostics that quote user-controlled text:resolve_config.py:67andresolve_customization.py:84—f"error: {error}\n", where the message carries the offending config path and tomllib's parse error.memlog.py:148— quotespath;memlog.py:154— quotes the--field key=valuepair straight from argv.Only stdout is pinned (
write_json_stdout). stderr is left at the platform default, so on a Windows console (cp1252) the filename the user needs in order to fix the problem comes back as escapes.Measured, same run with and without the pin:
Change
Generalizes the
pin_utf8helper already merged forbrain.pyin #2578 to the three scripts, and calls it on stderr atmain()entry.write_json_stdoutnow goes through the same helper instead of its own inlinereconfigure.errors=is passed through deliberately:reconfigure(encoding=...)alone resets the handler to"strict", which would silently downgrade stderr's POSIXbackslashreplacedefault and turn a diagnostic about an undecodable path into a traceback.Test
Adds one subprocess test that drives
resolve_customization.pywithPYTHONIOENCODING=cp1252against a project root whose path contains Turkish characters, and asserts the path appears readable in stderr with no traceback.Verified it discriminates: with the
pin_utf8(sys.stderr)line stripped the test fails on exactly that assertion; restored, it passes.src/scripts/tests— 42 passed (41 before, +1 new).Diff is +102 / -7 across three scripts and one test file.