Skip to content

Add more Exception classes for common exceptions #110

@dhagrow

Description

@dhagrow

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:

try:
    client.alter(...)
except pydgraph.errors.PendingTransactionError:
    # handle

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementSomething could be better.status/acceptedWe were able to reproduce the issue and accept to work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions