Skip to content

extract: write the output file as UTF-8 - #220

Open
adityakale2002 wants to merge 1 commit into
beancount:masterfrom
adityakale2002:fix/extract-output-utf8
Open

adityakale2002 wants to merge 1 commit into
beancount:masterfrom
adityakale2002:fix/extract-output-utf8

Conversation

@adityakale2002

Copy link
Copy Markdown

Fixes #206.

click.File("w") opens the -o file with the platform default encoding, which is cp1252 on Windows. beangulp extract -o FILE therefore failed with UnicodeEncodeError on any non-ASCII narration or payee and left a truncated file behind, while redirecting stdout worked.

This opens the output file as UTF-8 (click.File("w", encoding="utf-8")).

Test: added beangulp/cli_test.py. It runs extract -o in a subprocess with an ASCII default encoding (PYTHONUTF8=0, LC_ALL=C) and a Japanese narration. It fails without the change with the reported UnicodeEncodeError and passes with it. The rest of the suite passes (160 passed, 3 skipped); I excluded pdf_test.py because PyMuPDF would not install in my environment. ruff format is clean.

Disclosure: this fix and test were written with Claude Code's help; I reviewed and ran them.

🤖 Generated with Claude Code

click.File('w') opens the file with the platform default encoding, which
is cp1252 on Windows, so 'extract -o FILE' failed with UnicodeEncodeError
on any non-ASCII narration or payee, leaving a truncated file behind.
Redirecting stdout worked. Open the output file as UTF-8 instead.

Fixes beancount#206

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract -o FILE crashes on Windows with Unicode output, while stdout redirection works

1 participant