Skip to content

Skip non-UTF-8 environment entries instead of panicking in config loading - #4563

Merged
max-sixty merged 10 commits into
mainfrom
codex/config-non-utf8-environment
Oct 23, 2026
Merged

max-sixty merged 10 commits into
mainfrom
codex/config-non-utf8-environment

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

std::env::vars() panics when any environment entry is not valid UTF-8, so an unrelated variable could crash config loading. Read with vars_os and skip entries that don't decode; a non-UTF-8 WORKTRUNK_* override is ignored like any other unusable entry.

This was written by Claude Code on behalf of max-sixty

Comment thread tests/integration_tests/config_show.rs Resolved
@max-sixty

Copy link
Copy Markdown
Owner Author

do we really need this? I worry were making our code funky and complicated.

are there simpler ways to be conformant with alternative encodings etc? @worktrunk-bot

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The native-string handling is warranted here. vars() can panic while reading an unrelated non-UTF-8 entry, and var() cannot return a valid path containing native bytes. Filtering names from vars_os(), converting only actual config override values, and rendering paths lossily only for JSON keeps the conversion at the boundaries. I don't see a simpler standard-library path that preserves those behaviors.

One gap remains: WORKTRUNK_PROJECT_CONFIG_PATH is also a path override, and Repository::project_config_path() already reads it with var_os(), but the INFRA_VARS exclusion in parse_worktrunk_env_vars() omits it. A native-byte project config path is therefore diagnosed as an invalid user-config override, and UserConfig::load() rejects it even when the path itself is usable. Include this variable in the exclusion and exercise it alongside the other native-byte path fixtures.

@max-sixty max-sixty changed the title Handle native environment encodings without panicking during config loading Skip non-UTF-8 environment entries instead of panicking in config loading Oct 22, 2026
@max-sixty
max-sixty marked this pull request as ready for review October 22, 2026 23:55
@max-sixty
max-sixty merged commit d187abf into main Oct 23, 2026
39 checks passed
@max-sixty
max-sixty deleted the codex/config-non-utf8-environment branch October 23, 2026 00:35
max-sixty added a commit that referenced this pull request Oct 23, 2026
Unreadable system and user config files are silently ignored, allowing
commands such as `switch --create` to proceed with defaults. Load both
file layers through one ordered loop and distinguish an absent file from
a read failure. Strict commands report read failures; best-effort
callers retain usable settings from other layers. Missing-file behavior
and layer precedence stay the same.

The shared path removes 25 lines of duplicated loading logic. Update the
save-failure prompt test to make the path unwritable after the prompt
appears, using the existing callback; it now isolates a save failure
from a startup read failure.

Depends on #4563 and targets its branch. Validation: all four new
regressions reproduce branch creation with the old loader for
directories and invalid UTF-8 in user/system files. All 416 focused
config tests pass.

The required `cargo run -- hook pre-merge --yes` gate passed in the
combined audit checkout: 5,469 tests passed, one skipped, plus
formatting, Clippy, lockfile checks, doctests, and rustdoc. The
container runner supplied orphan reaping because its PID 1 does not reap
children.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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