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);
}

To handle a specific error, compare error.code with a constant on Aerospike.status. This example treats a missing record as a normal result:

try {
const record = await client.get(key);
console.info(record.bins);
} catch (error) {
if (error.code === Aerospike.status.ERR_RECORD_NOT_FOUND) {
console.info("Record not found");
} else {
throw error;
}
}

Common status codes

These are the Aerospike.status constants that application code most often checks for:

ConstantCodeReturned when
ERR_RECORD_NOT_FOUND2The record doesn’t exist, on a read, a delete, a read-only operate() call or one that requires the record to exist (such as touch()), or an update-only write.
ERR_RECORD_GENERATION3A write with a generation check finds that the record has changed. See Write only if the record is unchanged.
ERR_RECORD_EXISTS5A create-only write finds that the record already exists. See Create only if the record doesn’t exist.
ERR_BIN_EXISTS6A create-only bin write, such as an expression write with CREATE_ONLY, finds that the bin already exists.
ERR_BIN_NOT_FOUND17An expression write with UPDATE_ONLY finds no bin. String operations with UPDATE_ONLY succeed as a no-op instead.
ERR_INDEX_FOUND200createIndex() conflicts with an existing index, such as one with the same name and a different index type. Creating an index identical to an existing one succeeds.
ERR_INDEX_NOT_FOUND201A query filters on a bin that has no secondary index. Removing an index that doesn’t exist succeeds.
ERR_NO_MORE_CONNECTIONS-7The client has opened maxConnsPerNode connections to the node. See Connection pool and cluster tending.

Batch commands report each record’s status in its result rather than rejecting. See Create-only writes.

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.