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

Catching KeyError instead of IndexError #131

Open
kootenpv opened this issue Nov 26, 2016 · 1 comment
Open

Catching KeyError instead of IndexError #131

kootenpv opened this issue Nov 26, 2016 · 1 comment

Comments

@kootenpv
Copy link

kootenpv commented Nov 26, 2016

For example:

I created some indexed objects, but in the case one does not exist and one tries to use "single" (index['user_id']["1"].single), the following happens:

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/neo4jrestclient/iterable.py in single(self)
     65     def single(self):
     66         try:
---> 67             return self[0]
     68         except KeyError:
     69             return None

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/neo4jrestclient/iterable.py in __getitem__(self, index)
     29 
     30     def __getitem__(self, index):
---> 31         elto = super(Iterable, self).__getitem__(index)
     32         if self._attribute:
     33             return self._class(elto[self._attribute], update_dict=elto,

IndexError: list index out of range

We can see the code here:

https://github.com/versae/neo4j-rest-client/blob/master/neo4jrestclient/iterable.py#L68

I think what is meant is catching an IndexError rather than KeyError. Could that be the case?

@versae
Copy link
Owner

versae commented Nov 28, 2016

Yes, probably better to catch both. Thanks!

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

No branches or pull requests

2 participants