fix(windows): force UTF-8 console output at startup#744
fix(windows): force UTF-8 console output at startup#744hoyt-harness wants to merge 1 commit intogoogleworkspace:mainfrom
Conversation
…eworkspace#742) Call SetConsoleOutputCP(65001) via a thin inline FFI wrapper in output.rs before any output is produced, preventing CP-1252 mojibake for non-ASCII characters on Windows terminals. Also collapses a redundant nested if-in-match in helpers/script.rs to satisfy clippy::collapsible_match, which triggers on the latest stable toolchain.
🦋 Changeset detectedLatest commit: 8058aa7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where non-ASCII characters are incorrectly rendered in the Windows console due to legacy codepage inheritance. By explicitly setting the console output to UTF-8 at startup, the application ensures consistent character display across different Windows environments. Additionally, the PR includes a minor refactor to maintain clean code standards and includes a test case to verify the codepage configuration on Windows. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements a fix for Windows console output by forcing the UTF-8 codepage (65001) at startup to prevent character encoding issues. It also refactors the JSON file processing logic in script.rs using match guards for better readability and adds a changeset and unit tests for the new Windows-specific functionality. I have no feedback to provide.
Summary
Fixes #742.
On Windows,
gwsinherits the system console codepage (typically CP-1252 or CP-437). When Rust'sprintln!writes UTF-8 bytes, the console interprets them using the active codepage, producing mojibake for any non-ASCII characters in API responses (e.g. smart quotes, accented names, emoji).Fix: Call
SetConsoleOutputCP(65001)via a thin inline FFI shim at the very start ofmain(), before any output is produced. This tells the Windows Console to interpret subsequent output as UTF-8. The call is gated behind#[cfg(windows)]so non-Windows builds are unaffected.No new dependency is added — the function is part of
kernel32.dlland is called directly via anextern "system"block.Files changed
crates/google-workspace-cli/src/output.rsset_console_utf8()+ Windows-conditional testcrates/google-workspace-cli/src/main.rsset_console_utf8()at startupcrates/google-workspace-cli/src/helpers/script.rsif-in-matchto satisfyclippy::collapsible_matchon latest stable (lint trigger on Rust 1.87+; required forcargo clippy -- -D warningsto pass locally).changeset/fix-windows-utf8-console-codepage.mdThe
script.rschange is a ride-along lint fix — happy to split it into a separate PR if preferred.Test plan
cargo clippy -- -D warningspassescargo testpasses (702 tests pass; 2 pre-existing Windows-only failures inauth::tests::test_get_quota_project_*— those tests setHOMEbutdirs::home_dir()on Windows usesUSERPROFILE, unrelated to this PR)set_console_utf8_sets_codepage_65001test: callsSetConsoleOutputCP(65001)and thenGetConsoleOutputCP()— confirmed returns65001on Windows (skips assertion gracefully when no console is attached, e.g. in CI)🤖 Generated with Claude Code