New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_bool raises a different Exception than the other getters when key is missing #135

Closed
movermeyer opened this Issue Oct 12, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@movermeyer
Contributor

movermeyer commented Oct 12, 2017

The following code:

from pyhocon import ConfigFactory
config = ConfigFactory.parse_string("")

for getter in [config.get, config.get_string, config.get_list, config.get_int, config.get_float, config.get_config, config.get_bool]:
    try:
        getter("missing_value")
    except Exception as exc:
        print str(getter), type(exc)
        print "\t", exc

produces the following output:

<bound method ConfigTree.get of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_string of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_list of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_int of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_float of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_config of ConfigTree()> <class 'pyhocon.exceptions.ConfigMissingException'>
        u'No configuration setting found for key missing_value'
<bound method ConfigTree.get_bool of ConfigTree()> <class 'pyhocon.exceptions.ConfigException'>
        missing_value does not translate to a Boolean value

All the "getters", except get_bool, raise pyhocon.exceptions.ConfigMissingException, while get_bool raises pyhocon.exceptions.ConfigException.

This bug/inconsistency was introduced in the change from 0.3.35 -> 0.3.36.
Tested with Python 2.7.5

@movermeyer

This comment has been minimized.

Contributor

movermeyer commented Oct 12, 2017

This is a result of #120, which made ConfigMissingException inherit from KeyError as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment