fix: handle malformed config files (ParsingError) + comprehensive tests#68
Open
ProjectNobi wants to merge 1 commit intochutesai:mainfrom
Open
fix: handle malformed config files (ParsingError) + comprehensive tests#68ProjectNobi wants to merge 1 commit intochutesai:mainfrom
ProjectNobi wants to merge 1 commit intochutesai:mainfrom
Conversation
Addresses feedback from closed PR chutesai#65 and builds on Jon's fix in 959252d. Jon's commit (959252d) already handled: - NoOptionError missing from the auth-section try/except - Unguarded raw_config.get('api', 'base_url') call This PR adds one remaining gap + full test coverage: 1. raw_config.read(CONFIG_PATH) was unguarded against configparser.ParsingError (which includes MissingSectionHeaderError for files with no [section] headers). A malformed config.ini now raises NotConfigured with a clear message, or is silently skipped when CHUTES_ALLOW_MISSING=true — consistent with the rest of the error handling pattern. 2. tests/test_config.py — 12 unit tests covering every failure path: - Config file missing entirely - Config file empty - [auth] section absent - [auth] section present but options missing (NoOptionError) - [auth] section header only, no keys - Malformed file (no section headers → MissingSectionHeaderError) - All above with CHUTES_ALLOW_MISSING=true (no raise, returns defaults) - Valid [auth] without [api] → falls back to default URL - Valid full config ([auth] + [api]) - [api] section present but base_url key missing → falls back - CHUTES_API_URL env var override All 12 tests pass.
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.
Context
Follows up on closed #65 — addresses all feedback from @jondurbin:
Since #65, commit
959252dalready fixedNoOptionErrorand uninitialized config. This PR adds the one remaining gap: malformed config files that raiseParsingError(e.g. truncated files, missing section headers).Changes
chutes/config.py(10 lines)raw_config.read(CONFIG_PATH)in try/except forParsingErrorif not ALLOW_MISSING: raise NotConfigured(...)ParsingErrorfromconfigparsertests/test_config.py(275 lines, 12 tests)get_config()edge cases:All 12 tests pass.
T68Bot — Project Nobi