Skip to content

fix(excalidraw-diagram-generator): force UTF-8 stdout so add-arrow/add-icon don't crash on Windows#1914

Open
brainit-consulting wants to merge 2 commits into
github:stagedfrom
brainit-consulting:fix/excalidraw-windows-utf8
Open

fix(excalidraw-diagram-generator): force UTF-8 stdout so add-arrow/add-icon don't crash on Windows#1914
brainit-consulting wants to merge 2 commits into
github:stagedfrom
brainit-consulting:fix/excalidraw-windows-utf8

Conversation

@brainit-consulting
Copy link
Copy Markdown

Problem

On Windows, add-arrow.py and add-icon-to-diagram.py crash at the very end of an otherwise
successful run. Both finish by printing a check mark, e.g.:

print(f"✓ Successfully added arrow to diagram")

On a standard Windows console Python's stdout uses the cp1252 code page, which cannot encode
U+2713 (✓). That print raises UnicodeEncodeError, so the script exits with code 1 even though it
has already saved the file
. The edit lands, but any caller that checks the exit code sees a failure.
It is also easy to misdiagnose, because the traceback goes to stdout while stderr stays empty.

Repro (Windows, default code page):

python add-arrow.py diagram.excalidraw 0 0 100 100 --label "x"
...
Saving diagram
Error: 'charmap' codec can't encode character '✓' in position 0: character maps to <undefined>
# exit code 1, but diagram.excalidraw WAS modified

This makes the two scripts unreliable when driven from automation (or any tool that checks exit codes)
on Windows.

Fix

Reconfigure stdout to UTF-8 at the start of main() in both scripts. This is the same guard already
used by split-excalidraw-library.py
in the same scripts/ directory, so this just brings the other
two scripts in line:

if hasattr(sys.stdout, "reconfigure"):
    # Ensure consistent UTF-8 output on Windows consoles.
    sys.stdout.reconfigure(encoding="utf-8")

No behavior change on macOS/Linux; on Windows the success message now prints and the script exits 0.

Verification

On Windows with the default cp1252 console:

  • before: add-arrow.py ... -> exit 1, charmap error raised after the file was already saved
  • after: add-arrow.py ... -> prints ✓ Successfully added arrow to diagram, exit 0

Two files, +3/-0 each, no functional change beyond the encoding fix.

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This PR targets main, but PRs should target staged.

The main branch is auto-published from staged and should not receive direct PRs.
Please close this PR and re-open it against the staged branch.

You can change the base branch using the Edit button at the top of this PR,
or run: gh pr edit 1914 --base staged

@github-actions github-actions Bot added skills PR touches skills targets-main PR targets main instead of staged labels Jun 4, 2026
@brainit-consulting brainit-consulting changed the base branch from main to staged June 4, 2026 18:15
@github-actions github-actions Bot added branched-main PR appears to include plugin files materialized from main external-plugin PR updates plugins/external.json and removed skills PR touches skills targets-main PR targets main instead of staged labels Jun 4, 2026
@brainit-consulting brainit-consulting force-pushed the fix/excalidraw-windows-utf8 branch from cc71352 to 36cdc52 Compare June 4, 2026 18:18
…add-icon so the success print doesn't crash on Windows cp1252
…add-icon so the success print doesn't crash on Windows cp1252
@github-actions github-actions Bot removed branched-main PR appears to include plugin files materialized from main external-plugin PR updates plugins/external.json labels Jun 4, 2026
@github-actions github-actions Bot added skills PR touches skills skill-check-warning Skill validator reported warnings labels Jun 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

🔍 Skill Validator Results

⚠️ Warnings or advisories found

Scope Checked
Skills 1
Agents 0
Total 1
Severity Count
--- ---:
❌ Errors 0
⚠️ Warnings 1
ℹ️ Advisories 0

Summary

Level Finding
ℹ️ Found 1 skill(s)
ℹ️ [excalidraw-diagram-generator] 📊 excalidraw-diagram-generator: 5,862 BPE tokens [chars/4: 5,926] (comprehensive ✗), 43 sections, 22 code blocks
ℹ️ [excalidraw-diagram-generator] ⚠ Skill is 5,862 BPE tokens (chars/4 estimate: 5,926) — "comprehensive" skills hurt performance by 2.9pp on average. Consider splitting into 2–3 focused skills.
ℹ️ ✅ All checks passed (1 skill(s))
Full validator output ```text Found 1 skill(s) [excalidraw-diagram-generator] 📊 excalidraw-diagram-generator: 5,862 BPE tokens [chars/4: 5,926] (comprehensive ✗), 43 sections, 22 code blocks [excalidraw-diagram-generator] ⚠ Skill is 5,862 BPE tokens (chars/4 estimate: 5,926) — "comprehensive" skills hurt performance by 2.9pp on average. Consider splitting into 2–3 focused skills. ✅ All checks passed (1 skill(s)) ```

@brainit-consulting
Copy link
Copy Markdown
Author

Thanks for the heads-up. Retargeted this PR to staged and rebased the branch onto it, so the diff is just the intended change: the UTF-8 stdout guard in add-arrow.py and add-icon-to-diagram.py (+3/-0 each), matching the guard split-excalidraw-library.py already uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skill-check-warning Skill validator reported warnings skills PR touches skills

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant