Skip to content

Read and write default myclirc as UTF-8 - #2389

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
b84330808:fix-default-config-utf8
Oct 25, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
b84330808:fix-default-config-utf8

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Description

On Windows with a CJK code page (cp932 here, and cp936/cp949/cp950 fail the same way), mycli crashes on every startup unless Python's UTF-8 mode is on:

  File "...\mycli\config.py", line 153, in read_config_file
    config = SQLValuePreservingConfigObj(f, interpolation=False, encoding="utf8", list_values=list_values)
  ...
UnicodeDecodeError: 'cp932' codec can't decode byte 0x93 in position 7939: illegal multibyte sequence

The packaged myclirc is UTF-8 and has en dashes in the prompt comments ((00–23), (01–12), since 32fe310 / v1.54.0). But create_default_config() and write_default_config() open it with the locale encoding, and the first-run ~/.myclirc is also written with the locale encoding. User config files were already read as UTF-8.

#985 fixed the same crash in 2021 by removing a dash (#978, #998). This change reads and writes the file as UTF-8 instead, so the crash won't come back the next time the comments change.

Windows CI doesn't catch this because the runners use cp1252, and those bytes decode there (as mojibake). The new test runs both functions in a subprocess with -X warn_default_encoding -W error::EncodingWarning:mycli.config, so it fails on any OS if the default config is opened without an encoding again.

I used Claude Code to write this change.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

The packaged myclirc is UTF-8 and contains non-ASCII text (en dashes
in the prompt format comments), but it was opened with the locale
encoding. On Windows with a CJK code page such as cp932, mycli crashed
with UnicodeDecodeError on every startup, and writing ~/.myclirc on
first run would fail the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rolandwalker rolandwalker self-assigned this Oct 25, 2026
@rolandwalker

Copy link
Copy Markdown
Contributor

Thank you!

@rolandwalker
rolandwalker merged commit cb14efc into dbcli:main Oct 25, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

Going out now in release https://github.com/dbcli/mycli/releases/tag/v2.30.2 .

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.

2 participants