ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
277 stars 31 forks source link

TpeError exception on empty yaml parameter #105

Closed xoxys closed 5 years ago

xoxys commented 5 years ago

If you have the following source file:

logging:
  level: WARNING

and try to merge this file with this:

logging: 

you will get a TypeError Exception TypeError: 'NoneType' object is not iterable

I understand the issue and it's clear for me why this habbends if merge strategy is MS_DICT but is there a way to get a better error handling for this case?

ssato commented 5 years ago

Hi, thanks a lot for your report! I'll look into this asap and please wait for a while (maybe today).

xoxys commented 5 years ago

No, problem. For me it could be a valid solution to use the build-in schema validation in a try... except block to handle possible merge errors more user-friendly. I will play a bit with this in the meantime :)

ssato commented 5 years ago

Because the types of the value of "logging" of the first one ({}) and the second one (None) does not match at all, I don't think it's possible to merge them automatically with the merge strategy MS_DICT (default).

logging:
  level: WARNING   # :: {}
logging: <None>   # :: None, {} cannot be merged with None.

If you want to merge them, the appropriate strategy may be either MS_REPLACE or MS_NOREPLACE, or the second one should be rewritten such like:

logging: {}

I understand the issue and it's clear for me why this happends if merge strategy is MS_DICT but is there a way to get a better error handling for this case?

Catch TypeError might be the best way, I think.