It would be helpful to have a more Exception classes to make it easier to handle several common error cases. Currently, grpc.StatusCode.ABORTED is raised as AbortedError, but only by Txn.mutate() and Txn.commit(). To handle an aborted transaction for DgraphClient.alter(), the following is still required:
try:
client.alter(...)
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.ABORTED:
# handle
else:
raise
Other errors may not even have a StatusCode, and require something like this:
try:
client.alter(...)
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.UNKNOWN:
if e.details().startswith('Pending transactions found'):
# handle
else:
raise
else:
raise
I frequently see StatusCode.ABORTED, StatusCode.UNKNOWN (in my case, pending transactions), and StatusCode.DEADLINE_EXCEEDED (timeouts). Each of these can be resolved by retrying the operation, so it’s necessary to distinguish them from other error cases. It would be helpful if these could be caught as follows:
there are a couple of other places where a more specific Error type would be very helpful and would avoid clients of this library having to do checks on the error message for example
Some basic exceptions have been introduced in #135. Feel free to open an issue if there’s an additional exception that should be handled with a special Exception.
These changes will be available in the next release of pydgraph.