Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: PHP 1.1
Community Wiki and Resources
Wiki: PHP Client Library
PHP Client Library
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
3.1 Error Handling
Chapter Sections
Chapters

3.1.2. Error Codes and Constants

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.

Deprecated: 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 CodeDescription
COUCHBASE_SUCCESSOperation succeeded.
COUCHBASE_AUTH_CONTINUEInternal error message.
COUCHBASE_DELTA_BADVALIncrement/decrement on an object that isn’t a number.
COUCHBASE_E2BIGThe object is too big to be stored on the server.
COUCHBASE_EBUSYThe server is too busy to handle your request. Please try again later.
COUCHBASE_EINTERNALAn internal error in the Couchbase extension. You should probably submit a bug report for this.
COUCHBASE_ENOMEMOut of resources.
COUCHBASE_ERRORA "generic" error occured.
COUCHBASE_ETMPFAILTemporary failure. Try again.
COUCHBASE_KEY_EEXISTSThe key exists, but the CAS identifier provided did not match the one for the object in the cluster.
COUCHBASE_KEY_ENOENTThe key does not exist.
COUCHBASE_NETWORK_ERRORAn error occurred while trying to read/write data to the network.
COUCHBASE_NOT_MY_VBUCKETThe 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_STOREDThe object was not stored.
COUCHBASE_NOT_SUPPORTEDThe server knows about this command, but the datastore doesn't support it.
COUCHBASE_UNKNOWN_COMMANDThe server did not understand the command we sent. You may be using a cluster that is incompatible with the client library.
COUCHBASE_UNKNOWN_HOSTFailed to lookup the host.