Skip to content

Fixed errors caused by invalid config files.#1995

Merged
jensens merged 2 commits intocookiecutter:mainfrom
alanverresen:issue1994
Jan 23, 2024
Merged

Fixed errors caused by invalid config files.#1995
jensens merged 2 commits intocookiecutter:mainfrom
alanverresen:issue1994

Conversation

@alanverresen
Copy link
Copy Markdown
Contributor

Fixes a bug as described in issue #1994, and an additional bug.

This commit fixes two similar errors caused by configuration files
with unexpected contents:

- if the config file is empty, then yaml.safe_load(stream) returns
  None instead of an (empty) dictionary
- if the config file has an array as its top-element, then
  yaml.safe_load(stream) returns an array instead of a dictionary

In both cases, merge_configs(default, overwrite) would raise an
exception due to only expecting a dictionary as an argument. These
two cases are now handled as follows:

- if the config file is empty, the result is an empty dictionary
  resulting in the default config being used
- if the config file does not have an object as its top-level
  element, then an exception is raised to inform the user
- rewrote name and doc of existing test for clarity
- adds a test that covers the case where the YAML config file
  contains multiple documents
- needed to add exception to linter because YAML files with multiple
  docs are flagged
@alanverresen
Copy link
Copy Markdown
Contributor Author

Although it was not within the scope of the original issue, I added another test case that covers the case where the config file contains multiple YAML documents, because it's closely related.

@jensens jensens added the bug This issue/PR relates to a bug. label Jan 23, 2024
@jensens jensens merged commit e522b69 into cookiecutter:main Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants