Skip to content
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

Confusing exceptions #218

Closed
cwells opened this issue Mar 16, 2022 · 2 comments
Closed

Confusing exceptions #218

cwells opened this issue Mar 16, 2022 · 2 comments
Labels

Comments

@cwells
Copy link

cwells commented Mar 16, 2022

I would expect the following to raise a KeyError, not a BoxError:

In [17]: b = Box(box_dots=True)

In [18]: b['a.b']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
lib64/python3.8/site-packages/box/box.py in __getitem__(self, item, _ignore_default)
    487         try:
--> 488             return super().__getitem__(item)
    489         except KeyError as err:

KeyError: 'a.b'

During handling of the above exception, another exception occurred:

BoxError                                  Traceback (most recent call last)
<ipython-input-18-e8e887ae1af6> in <module>
----> 1 b['a.b']

lib64/python3.8/site-packages/box/box.py in __getitem__(self, item, _ignore_default)
    493             if self._box_config["box_dots"] and isinstance(item, str) and ("." in item or "[" in item):
    494                 try:
--> 495                     first_item, children = _parse_box_dots(self, item)
    496                 except BoxError:
    497                     if self._box_config["default_box"] and not _ignore_default:

lib64/python3.8/site-packages/box/box.py in _parse_box_dots(bx, item, setting)
     91     if setting and "." in item:
     92         return item.split(".", 1)
---> 93     raise BoxError("Could not split box dots properly")
     94 
     95 

BoxError: Could not split box dots properly
@cdgriffith cdgriffith added the bug label Mar 16, 2022
@cdgriffith
Copy link
Owner

Agreed, that use case does not seem to be working properly. Thanks for bringing it up!

cdgriffith added a commit that referenced this issue Mar 16, 2022
* Fixing #218 Box dots would not raise KeyError on bad key (thanks to Cliff Wells)
* Fixing #217 wording in readme overview needed updated (thanks to Julie Jones)
@cdgriffith
Copy link
Owner

Fixed in 6.0.1 https://github.com/cdgriffith/Box/releases/tag/6.0.1 Thanks again for pointing that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants