Skip to content

Error handling

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Each database operation returns an error object in the callback function:

  • On success, null will be returned
  • On error, the error object is populated.

Error Object

Error objects are of class AerospikeError and include the following properties:

PropertyDescription
codeThe operation status.
messageThe message corresponding to an error code. Can be an empty string if the operation completed successfully.
funcThe function in which the error occurred. Can be null if not captured properly in the operation.
fileThe file in which the error occurred. Can be null if not captured properly in the operation.
lineThe line number in the file in which the error occurred. Can be 0 if not captured properly in the operation.

This example handles an error from a put() operation:

try {
await client.put(key, bins);
} catch (error) {
console.error("error: %s [%d]\n%s", error.message, error.code, error.stack);
process.exit(-1);
}

Server error details

Aerospike Database 8.2.0 can return a numeric subcode and a message on failed operations. Enable this by setting errorDetailVerbosity on the policy passed to the operation, then read the subcode from the error object:

const Aerospike = require('aerospike')
const policy = { errorDetailVerbosity: Aerospike.errorDetailVerbosity.SUBCODE }
try {
await client.get(key, policy)
} catch (error) {
console.error(
'status=%d subcode=%d message=%s',
error.code, error.subcode, error.message
)
}

Verbosity levels are on the aerospike/errorDetailVerbosity module:

ValueConstantServer returns
0Aerospike.errorDetailVerbosity.NONETop-level status only (default)
1Aerospike.errorDetailVerbosity.SUBCODESubcode
2Aerospike.errorDetailVerbosity.MESSAGESubcode and message
33Subcode, message, and expression trace
  • AerospikeError.subcode is the numeric subcode, or 0 when the server didn’t return one. Dispatch on the (code, subcode) pair, never the subcode alone. Constants are on the aerospike/subcode module (Aerospike.subcode.*). See Error subcodes.
  • error.message includes the server’s detail text at verbosity 2.

The Node.js client does not decode the verbosity-3 expression trace into a data structure, but it does return the expression trace in the error message field. To debug expression failures with a trace, use the Java or Go client.

See Server error details for behavior, operator caps, and coverage, and the Client Compatibility Matrix for the Node.js client version that pairs with Database 8.2.0.