Raise a clear error when fenn.yaml is empty or not a mapping - #323
Open
pcbeingused333 wants to merge 1 commit into
Open
Raise a clear error when fenn.yaml is empty or not a mapping#323pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Parser.load_configuration did 'self._args = yaml.safe_load(f)' then 'self._args["project"] = ...'. An empty config file makes safe_load return None, and a top-level list/scalar makes it a non-dict, so the next line raised a bare 'TypeError: NoneType object does not support item assignment' (or 'list indices must be integers') instead of telling the user their config is wrong. Both app.py and 'fenn grid' hit this. Validate the parsed value and raise ValueError with a message naming the file and the problem, mirroring _config_missing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018uqJtTJWawYLVA5EdpUmho
Contributor
Author
|
The |
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.
Problem
Parser.load_configuration:yaml.safe_loadreturnsNonefor an empty file and alist/str/intfor a top-level non-mapping, so the next line raises a bareTypeError: 'NoneType' object does not support item assignment(orlist indices must be integers or slices, not str). The user just gets a stack trace into fenn internals instead of being told their config file is empty or malformed.Both entry points hit it:
App._load_configurationandfenn grid(_parse_grid).Fix
Validate the parsed value and raise
ValueErrorwith a message that names the file and the problem, mirroring the existing_config_missinghelper.Tests
New
tests/unit/test_parser.py: happy path, missing file, empty file, non-mapping. The empty/non-mapping cases raiseTypeErroronmainandValueErrorwith the fix (verified:pytest tests/unit— 922 passed,ruff check/formatclean).