New in version 1.2.1.
Couchbase exceptions may be caught in two flavors. You can catch an exception either by its explicit subclass or by its base class.
Normally you should catch exception classes for cases you don’t have a specific handler for, and error details for things that need special handling. Thus for example:
try:
cb.get("foo")
except NotFoundError:
print("Item does not exist")
except CouchbaseTransientError:
print("Transient error received. Handling and backing off")
Where NotFoundError is a specific error detail code indicating the item has not been found, and CouchbaseTransientError is an error category indicating the specific cause is likely transient.
As your application evolves you may wish to examine the specific error code received as well as log the information to the screen.
Employing the error classifier pattern will prove scalable when additional error codes are added to the library. Sticking to catching error codes rather than specific error categories will allow your application to deal gracefully with future error codes so long as they match a specific category.
You may also employ a different use model, for example:
try:
cb.get("foo")
except CouchbaseError as e:
if e.is_data and isintance(e, NotFoundError):
# handle not found
pass
elif e.is_network:
print("Got network error")
elif e.is_data:
print("Got other data-related error")
else:
print("Got unhandled error code")
This object is the base class for all exceptions thrown by Couchbase which are specific to the library. Other standard Python exceptions may still be thrown depending on the condition.
Base exception for Couchbase errors
This is the base class for all exceptions thrown by Couchbase
Exception Attributes
- rc¶
The return code which caused the error
A MultiResult object, if this exception was thrown as part of a multi-operation. This contains all the operations (including ones which may not have failed)
- inner_cause¶
If this exception was triggered by another exception, it is present here.
- key¶
If applicable, this is the key which failed.
- csrc_info¶
A tuple of (file, line) pointing to a location in the C source code where the exception was thrown (if applicable)
- categories[source]¶
An integer representing a set of bits representing various error categories for the specific error as returned by libcouchbase.
- is_data[source]¶
True if this error is a negative reply from the server (see CouchbaseDataError)
- is_transient[source]¶
True if this error was likely caused by a transient condition (see CouchbaseTransientError)
- is_fatal[source]¶
True if this error indicates a likely fatal condition for the client. See CouchbaseFatalError
- is_network[source]¶
True if errors were received during TCP transport. See CouchbaseNetworkError
These categories form the base exception classes
Base class for network-related errors. These indicate issues in the low level connectivity
Base class for errors possibly caused by malformed input
Base class for errors which are likely fatal and require reinitialization of the instance
The following codes are exception details. They all derive from CouchbaseError. Many of them will have multiple error categories and thus be inherited from multiple exception categories.
Bases: couchbase.exceptions.CouchbaseError
Invalid argument
A given argument is invalid or must be set
Bases: couchbase.exceptions.CouchbaseError
Failed to decode or encode value
Bases: couchbase.exceptions.CouchbaseError
Authentication failed
You provided an invalid username/password combination.
Bases: couchbase.exceptions.CouchbaseError
The given value is not a number
The server detected that operation cannot be executed with requested arguments. For example, when incrementing not a number.
Bases: couchbase.exceptions.CouchbaseError
Object too big
The server reported that this object is too big
Bases: couchbase.exceptions.CouchbaseError
The cluster is too busy
The server is too busy to handle your request right now. please back off and try again at a later time.
Bases: couchbase.exceptions.CouchbaseError
Internal Error
Internal error inside the library. You would have to destroy the instance and create a new one to recover.
Bases: couchbase.exceptions.CouchbaseError
Invalid arguments specified
Bases: couchbase.exceptions.CouchbaseError
The server ran out of memory
Bases: couchbase.exceptions.CouchbaseError
An invalid range specified
Bases: couchbase.exceptions.CouchbaseError
A generic error
Bases: couchbase.exceptions.CouchbaseError
Temporary failure (on server)
The server tried to perform the requested operation, but failed due to a temporary constraint. Retrying the operation may work.
This error may also be delivered if the key being accessed was locked.
Bases: couchbase.exceptions.CouchbaseError
The key already exists (with another CAS value)
This exception may be thrown during an add() operation (if the key already exists), or when a CAS is supplied and the server-side CAS differs.
Bases: couchbase.exceptions.CouchbaseError
The key does not exist
Bases: couchbase.exceptions.CouchbaseError
Failed to open shared object
Bases: couchbase.exceptions.CouchbaseError
Failed to locate the requested symbol in the shared object
Bases: couchbase.exceptions.CouchbaseNetworkError
Network error
A network related problem occured (name lookup, read/write/connect etc)
Bases: couchbase.exceptions.CouchbaseError
The vbucket is not located on this server
The server who received the request is not responsible for the object anymore. (This happens during changes in the cluster topology)
Bases: couchbase.exceptions.CouchbaseError
The object was not stored on the server
Bases: couchbase.exceptions.CouchbaseError
Not supported
The server doesn’t support the requested command. This error differs from couchbase.exceptions.UnknownCommandError by that the server knows about the command, but for some reason decided to not support it.
Bases: couchbase.exceptions.CouchbaseError
The server doesn’t know what that command is
Bases: couchbase.exceptions.CouchbaseNetworkError
The server failed to resolve the requested hostname
Bases: couchbase.exceptions.CouchbaseNetworkError
Protocol error
There is something wrong with the datastream received from the server
Bases: couchbase.exceptions.CouchbaseError
The operation timed out
Bases: couchbase.exceptions.CouchbaseNetworkError
Failed to connect to the requested server
Bases: couchbase.exceptions.CouchbaseError
The requested bucket does not exist
Bases: couchbase.exceptions.CouchbaseError
The client ran out of memory
Bases: couchbase.exceptions.CouchbaseError
Temporary failure (on client)
The client encountered a temporary error (retry might resolve the problem)
Bases: couchbase.exceptions.CouchbaseError
Invalid handle type
The requested operation isn’t allowed for given type.
Bases: couchbase.exceptions.CouchbaseError
HTTP error