Repository navigation
Skip non-UTF-8 environment entries instead of panicking in config loading - #4563
Conversation
|
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
left a comment
There was a problem hiding this comment.
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.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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]>
std::env::vars()panics when any environment entry is not valid UTF-8, so an unrelated variable could crash config loading. Read withvars_osand skip entries that don't decode; a non-UTF-8WORKTRUNK_*override is ignored like any other unusable entry.