Force UTF-8 stdout so validate-schema hook doesn't crash on Windows (cp1252)#158
Draft
voipcomjohn wants to merge 1 commit into
Draft
Force UTF-8 stdout so validate-schema hook doesn't crash on Windows (cp1252)#158voipcomjohn wants to merge 1 commit into
voipcomjohn wants to merge 1 commit into
Conversation
…cp1252) On Windows the console defaults to cp1252, which can't encode the U+1F6D1 / U+26A0 status emoji this hook prints when it finds schema issues. As soon as the validator hits a placeholder or deprecated @type it raises UnicodeEncodeError (exit 1) instead of cleanly blocking the edit (exit 2), so the findings never reach the user. Reconfigure stdout/stderr to UTF-8 at the top of main(), guarded in try/except so it's a no-op where unavailable. No other behavior change. Co-Authored-By: Claude Opus 4.8 <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.
Problem
On Windows the console defaults to cp1252, which can't encode the status emoji (
U+1F6D1andU+26A0) thathooks/validate-schema.pyprints when it finds schema issues. The moment the validator detects a placeholder or a deprecated@typein an HTML file's JSON-LD, it crashes:So on Windows the
PostToolUsehook exits1with a traceback exactly when it should be cleanly blocking the edit (exit2), and the findings never reach the user. EveryWrite/Editthat trips the emoji path fails this way.Fix
Reconfigure
stdout/stderrto UTF-8 at the top ofmain(), guarded intry/exceptso it's a harmless no-op on streams that don't support it. No other behavior change.Testing
Windows 11 + Python 3.12, against an HTML file whose JSON-LD contains
[Business Name],[Phone], and@type: HowTo.Before:
UnicodeEncodeError, exit 1.After (exit 2, cleanly blocking):
Clean and non-HTML files still exit 0 silently.
🤖 Generated with Claude Code