Conversation
An empty or comment-only YAML file parses to nil, which crashed from_hash with NoMethodError. Treat it as an empty config. A file whose top level was a list either crashed (JSON) or silently set each element as an option with a nil value (YAML). Raise an ArgumentError that names the file instead. Signed-off-by: Tim Smith <tsmith84@proton.me>
tas50
force-pushed
the
fix-empty-and-non-hash-config-files
branch
from
September 28, 2026 02:03
627428a to
2d4ba3e
Compare
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.
Summary
Empty YAML files crashed. An empty or comment-only YAML file parses to
nil, sofrom_file("config.yml")raisedNoMethodError: undefined method 'each' for nil. It is now treated as an empty config. A newly created config file with nothing set yet is common.Files whose top level wasn't a mapping failed badly:
[1, 2]raisedNoMethodError: undefined method 'to_sym' for an instance of Integer.- one/- tworaised nothing. It silently set options namedoneandtwotonil.Both now raise
ArgumentError: config.yml must contain a mapping of config options at the top level, not Array.The check lives in a new private
from_parsed_filehelper used byfrom_yamlandfrom_json. TOML is unaffected, since a TOML document is always a table. An empty JSON file already fails clearly withJSON::ParserError, so it is left alone.Tests
Added specs for an empty YAML file, a comment-only YAML file, a top-level YAML list, and a top-level JSON array. All four failed before the change. The full suite passes and cookstyle is clean.