Skip to content

Raise a clear error when fenn.yaml is empty or not a mapping - #323

Open
pcbeingused333 wants to merge 1 commit into
pyfenn:mainfrom
pcbeingused333:fix/parser-empty-config
Open

Raise a clear error when fenn.yaml is empty or not a mapping#323
pcbeingused333 wants to merge 1 commit into
pyfenn:mainfrom
pcbeingused333:fix/parser-empty-config

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Problem

Parser.load_configuration:

with open(self._config_file) as f:
    self._args = yaml.safe_load(f)
    self._args["project"] = self._config_file.stem

yaml.safe_load returns None for an empty file and a list/str/int for a top-level non-mapping, so the next line raises a bare TypeError: 'NoneType' object does not support item assignment (or list 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_configuration and fenn grid (_parse_grid).

Fix

Validate the parsed value and raise ValueError with a message that names the file and the problem, mirroring the existing _config_missing helper.

Tests

New tests/unit/test_parser.py: happy path, missing file, empty file, non-mapping. The empty/non-mapping cases raise TypeError on main and ValueError with the fix (verified: pytest tests/unit — 922 passed, ruff check/format clean).

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
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

The pre-commit check is red on the ty hook, but that is pre-existing on main (commit 0d1862e fails the same job, on fenn/experimental/vision/normalize.py and fenn/logging.py — neither touched here). ruff check / ruff format pass and ty check fenn/parser.py is clean; the four test jobs are the relevant ones and they are green.

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.

1 participant