algorithmiaio/algorithmia-python

Exceptions too broad

Closed this issue · 2 comments

Hi Algorithmia,

It would appear most exceptions within this python client are the general Exception class:

$ grep -r "Exception" *
Algorithmia/algo_response.py:            raise AlgoException(responseJson['error'])
Algorithmia/algo_response.py:class AlgoException(Exception):
Binary file Algorithmia/acl.pyc matches
Algorithmia/util.py:            raise Exception('Invalid path')
Algorithmia/datadirectory.py:            raise Exception("Directory creation failed: " + str(response.content))
Algorithmia/datadirectory.py:            raise Exception(result['error']['message'])
Algorithmia/datadirectory.py:            raise Exception('Unable to get permissions:' + str(response.content))
Algorithmia/datadirectory.py:            raise Exception('Unable to update permissions: ' + response.json()['error']['message'])
Algorithmia/datadirectory.py:                raise Exception("Directory iteration failed: " + str(response.content))
Binary file Algorithmia/datadirectory.pyc matches
Binary file Algorithmia/datafile.pyc matches
Binary file Algorithmia/algorithm.pyc matches
Algorithmia/algorithm.py:            raise Exception('Invalid algorithm URI: ' + algoRef)
Algorithmia/algorithm.py:                raise Exception(response.text)
Algorithmia/algorithm.py:                raise Exception(response.text)
Algorithmia/algorithm.py:                raise Exception(responseJson['error']['message'])
Algorithmia/acl.py:            raise Exception('Response does not contain read ACL')
Algorithmia/acl.py:                raise Exception('Invalid acl string %s' % (acl_list[0]))
Binary file Algorithmia/util.pyc matches
Algorithmia/datafile.py:            raise Exception('file does not exist - {}'.format(self.path))
Algorithmia/datafile.py:            raise Exception('file does not exist - {}'.format(self.path))
Algorithmia/datafile.py:            raise Exception('file does not exist - {}'.format(self.path))
Algorithmia/datafile.py:            raise Exception('file does not exist - {}'.format(self.path))
Algorithmia/datafile.py:                raise Exception(result['error']['message'])
Algorithmia/datafile.py:            raise Exception("Must put strings or binary data. Use putJson instead")
Algorithmia/datafile.py:            raise Exception(result['error']['message'])
Algorithmia/datafile.py:                raise Exception(result['error']['message'])
Algorithmia/datafile.py:            raise Exception(result['error']['message'])
Binary file Algorithmia/algo_response.pyc matches
README.md:API errors and Algorithm exceptions will result in calls to `pipe` throwing an `AlgoException`:
README.md:# Algorithmia.algo_response.AlgoException: algorithm algo://util/whoopsWrongAlgo not found
Test/datafile_test.py:        except Exception as e:
Test/datafile_test.py:        except Exception as e:
Test/datadirectorytest.py:        self.assertRaises(Exception, dd.delete)
Test/utiltest.py:        self.assertRaises(Exception, getParentAndBase, '/')
Test/utiltest.py:        self.assertRaises(Exception, getParentAndBase, '')
Test/utiltest.py:        self.assertRaises(Exception, getParentAndBase, 'a/')

It would be useful to have more specific Exceptions for try: except handling. For example, for the exception here, perhaps an IOError would be more suitable?

Thanks

I agree with your point that we should use more specific exceptions. I think IOError is not quite the right one because in Python 3.3 it was merged into OSError (which doesn't feel quite right either).

I think a better solution would be custom APIError or some variation on that.

pmcq commented

Closed in PR above and most recent version of algorithmia client