Skip to content

Error handling

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Async APIs such as client.get() reject with an AerospikeError on failure. Callback-style APIs pass null on success or an AerospikeError on failure.

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.
subcodeServer error-detail subcode, or 0 if the server returned none. Requires errorDetailVerbosity on the policy and Aerospike Database 8.2.0 or later (Node.js client 7.0.0 and later). See Server error details.

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:

import Aerospike from '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
3Aerospike.errorDetailVerbosity.EXP_TRACESubcode, 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 Aerospike.errorDetailVerbosity.MESSAGE (level 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 matrix for the Node.js client version that pairs with Database 8.2.0.