Repository navigation
fix(no-ticket): read and rewrite config files as UTF-8 - #562
Open
cloudsmith-iduffy wants to merge 5 commits into
Open
cloudsmith-iduffy wants to merge 5 commits into
cloudsmith-iduffy wants to merge 5 commits into
Conversation
The CLI read config.ini and credentials.ini with the locale encoding. On Windows that is cp1252, so a UTF-8 file with Cyrillic text failed to load. The CLI now reads a file as UTF-8 and uses the locale encoding only when UTF-8 decoding fails. When the CLI changes a file, it writes the file back in the same encoding. A file that the CLI cannot decode now gives an error with the file path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Both encoding-test assertions reject native Windows line endings, causing all six parameterized cases to fail on the target platform.
1 open issue
What changed in this PR
This PR fixes Windows encoding failures when the CLI reads or updates config.ini and credentials.ini, while retaining support for locale-encoded files.
Changes:
- Detect each file’s encoding, preserving UTF-8 byte order marks and using UTF-8 for new files.
- Report the affected path when a configuration file cannot be decoded.
- Add encoding regression tests and register the Windows test marker.
| File | Description |
|---|---|
pyproject.toml |
Registers the windows pytest marker. |
cloudsmith_cli/cli/tests/test_unexpected_errors.py |
Checks actionable decoding errors without Sentry reporting. |
cloudsmith_cli/cli/tests/test_config_encoding.py |
Tests UTF-8, BOM, and cp1252 read/rewrite behavior. |
cloudsmith_cli/cli/config.py |
Adds per-file encoding detection for reads and updates. |
CHANGELOG.md |
Documents encoding support and improved errors. |
Review effort: Balanced
Fix line endings in workspace path assertion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
…ewrite-utf8 # Conflicts: # CHANGELOG.md Co-authored-by: cloudsmith-iduffy <178375997+cloudsmith-iduffy@users.noreply.github.com>
Contributor
Co-authored-by: cloudsmith-iduffy <178375997+cloudsmith-iduffy@users.noreply.github.com>
cloudsmith-iduffy
enabled auto-merge (squash)
October 29, 2026 10:59
This branch has not been deployed
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.

Description
On Windows, the CLI reads
config.iniandcredentials.iniin the locale encoding, which is usually cp1252. click-configfile passes no encoding toconfigparser, and the code that changes the files (save_workspaceaftercloudsmith auth, and_set_api_keyforlogin,logoutandtokens ... --save-config) does the same. A UTF-8 file with Cyrillic text fails because cp1252 has no character for the bytes 0x81, 0x8D, 0x8F, 0x90 and 0x9D (for example, "с" isD1 81). So every command fails, not onlyauthandlogout.The CLI now picks the encoding for each file:
Joséstill loads, and a rewrite keeps the file byte for byte.ConfigReader.read_configreplaces the click-configfile version so that it can give the encoding toconfigparserfor each file. The other logic is the same as the click-configfile code.When the CLI cannot decode a file in either encoding, the error now gives the path. Sentry CLOUDSMITH-CLI-K is an example of this.
Before (Windows, UTF-8
config.iniwith a Cyrillic comment):After: the command runs.
Before (a file that is not UTF-8, on macOS or Linux):
After:
Type of Change
Additional Notes
é. The exit code for a file that the CLI cannot decode stays 1. The error is now a clean message, not a rawUnicodeDecodeError, and the CLI still does not report it to Sentry.MissingSectionHeaderError, as it does today. That error also gives the path.windowsmarker. This PR adds the marker topyproject.tomlwith the same line as fix(no-ticket): print ASCII text in mcp configure, download and update #525 and fix(no-ticket): read and write .npmrc as UTF-8 #555.git merge-treeconflicts with other open PRs:cloudsmith_cli/cli/config.py, 2 hunks in_set_api_key. That PR adds lines next to the twoopen(...)lines. To resolve, keep its new lines and keep theencoding=_get_file_encoding(path)argument from this PR. There is also a conflict inCHANGELOG.mdunder### Fixed.CHANGELOG.mdonly.config.pymerges cleanly. Thesave_workspacesignature is the same as in fix(no-ticket): save the new API key to the user-level credentials file #541.cloudsmith_cli/cli/config.py, 1 hunk where thechmodblock meets the writeopen(...). Resolve it in the same way as fix(no-ticket): keep credentials.ini sections and save missing API keys #533. There is also a conflict inCHANGELOG.md.🤖 Generated with Claude Code