fix: raise ValueError on malformed YAML instead of leaking the parser's exception (#282) - #291
Open
patchwright wants to merge 1 commit into
Open
Conversation
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
Fixes #282. When
parse_yamlis given malformed YAML, the underlying parser's exception (PyYAML'syaml.scanner.ScannerError/ ruamel'sYAMLError) escapes as a raw stack trace instead of a clean error. Confirmed on master HEAD5046af8.Root cause
_pyyamland_ruamelinyamale/readers/yaml_reader.pycallyaml.load_all(...)without catching the parser's error, so it propagates straight out ofparse_yaml.Fix
Wrap each parser's
load_allcall in a try/except for its own error type (yaml.YAMLErrorfor PyYAML,ruamel.yaml.YAMLErrorfor ruamel) and re-raise asValueErrorwith the original message chained viafrom e. No API change; ~8 lines.How to test
Regression test added in
yamale/readers/tests/test_bad_file.py, parametrized over pyyaml/PyYAML/ruamel. Full suite green (171 passed).Backward compatibility
No breaking changes. Only the exception type for malformed input changes (raw parser error ->
ValueError), which is the behavior requested in #282.Assisted-by: Claude (code generation, reviewed and tested locally)