Do not let the console encoding decide the exit code - #3
Merged
Conversation
The Markdown report contains em dashes and status emoji, and the final print() sent it to stdout under the platform default encoding. On a console that cannot represent those characters the print raised UnicodeEncodeError, so the gate exited non-zero with a traceback even when every reference resolved -- a clean bibliography reported as a failed check. Seen on a Japanese Windows shell (cp932) while evaluating the action for a LaTeX repository; PYTHONIOENCODING=ascii reproduces it anywhere. The report and GITHUB_OUTPUT files already opened with encoding="utf-8"; this gives stdout the same treatment (reconfigure to UTF-8 with errors="replace", plus a lossy fallback if stdout cannot be reconfigured), so the exit code always reflects the reference check rather than the terminal. Adds a CI job that runs the gate under ascii / cp932 / utf-8 stdout and asserts both directions: a clean record exits 0 with no traceback, a broken record still exits 1. The existing Linux-only smoke test could not have caught this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The bug
The final
print(report)writes to stdout under the platform default encoding, while the report contains em dashes and status emoji. On a console that cannot encode them the print raisesUnicodeEncodeError, the script dies, and the gate exits non-zero even when every reference resolved — a clean bibliography is reported as a failed check.Found on a Japanese Windows shell (cp932) while evaluating this action for a LaTeX paper repository.
PYTHONIOENCODING=asciireproduces it on any platform:CI is unaffected (Linux, UTF-8), so this only bites people running the gate locally — exactly when they are debugging a bibliography.
The fix
--reportand--github-outputalready open withencoding="utf-8"; stdout now gets the same treatment: reconfigure to UTF-8 witherrors="replace", plus a lossy fallback if stdout cannot be reconfigured (replaced by a StringIO in tests, for instance). The exit code then always reflects the reference check rather than the terminal. Report content is unchanged, and under ascii stdout it is still printed in full UTF-8.Test
The existing smoke job is Linux/UTF-8 only and could not have caught this, so the PR adds an
encodingjob that runs the gate underascii,cp932andutf-8stdout and asserts both directions — a clean record exits 0 with no traceback, a broken record still exits 1. Verified locally before pushing:🤖 Generated with Claude Code