The PHP client library defines the following error codes and constants. These can be used against the return value for most operations to determine whether they succeeded, or failed, and in the event of a failure, what the underlying cause was. The constants are distributed between both generic interface errors, and operation specific errors. Check the corresponding API call tables for information on which errors are raised by each operation.
You can use the getResultCode() and
getResultMessage() methods to obtain
the error code and message for each operation. You can use these
in combination with the error constants to determine a specific
course of action when an operation fails, for example:
$cb->replace("fork", "Hello World!", 10); if ($cb->getResultCode() === COUCHBASE_KEY_ENOENT) { // Doesn't exist, add it first $cb->add("fork", "Hello World!", 10); echo "Key added (didn't exist)\n"; } elseif ($cb->getResultCode() === SUCCESS) { echo "Key updated\n"; } else { echo "Error occurred: ", $cb->getResultMessage(), "<br/>"; }
In the above example, an update operation is attempted on a key
which must already exist. If Couchbase Server returns an error
that the key didn't exist, add() is
used to create the key. If the operation was successful, we
output a success message. For all other errors, the error
message is generated.
The getResultCode() and
getResultMessage() return the error
from the previous API call.
getResultCode() and
getResultMessage() Deprecated
The getResultCode() and
getResultMessage() are deprecated and
will be removed in a future release. The PHP exception system
will replace the functionality of these two methods.
A full list of the constants and error messages available for each operation as shown in Table 3.2, “PHP Error Codes and Constants”.
Table 3.2. PHP Error Codes and Constants
| Error Code | Description |
|---|---|
COUCHBASE_SUCCESS | Operation succeeded. |
COUCHBASE_AUTH_CONTINUE | Internal error message. |
COUCHBASE_DELTA_BADVAL | Increment/decrement on an object that isn’t a number. |
COUCHBASE_E2BIG | The object is too big to be stored on the server. |
COUCHBASE_EBUSY | The server is too busy to handle your request. Please try again later. |
COUCHBASE_EINTERNAL | An internal error in the Couchbase extension. You should probably submit a bug report for this. |
COUCHBASE_ENOMEM | Out of resources. |
COUCHBASE_ERROR | A "generic" error occured. |
COUCHBASE_ETMPFAIL | Temporary failure. Try again. |
COUCHBASE_KEY_EEXISTS | The key exists, but the CAS identifier provided did not match the one for the object in the cluster. |
COUCHBASE_KEY_ENOENT | The key does not exist. |
COUCHBASE_NETWORK_ERROR | An error occurred while trying to read/write data to the network. |
COUCHBASE_NOT_MY_VBUCKET | The command was sent to the wrong server. This problem may occur if someone added/removed a node to the cluster. Retrying the operation may solve the problem. |
COUCHBASE_NOT_STORED | The object was not stored. |
COUCHBASE_NOT_SUPPORTED | The server knows about this command, but the datastore doesn't support it. |
COUCHBASE_UNKNOWN_COMMAND | The server did not understand the command we sent. You may be using a cluster that is incompatible with the client library. |
COUCHBASE_UNKNOWN_HOST | Failed to lookup the host. |