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:
| Property | Description |
|---|---|
code | The operation status. |
message | The message corresponding to an error code. Can be an empty string if the operation completed successfully. |
func | The function in which the error occurred. Can be null if not captured properly in the operation. |
file | The file in which the error occurred. Can be null if not captured properly in the operation. |
line | The line number in the file in which the error occurred. Can be 0 if not captured properly in the operation. |
subcode | Server 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:
| Value | Constant | Server returns |
|---|---|---|
| 0 | Aerospike.errorDetailVerbosity.NONE | Top-level status only (default) |
| 1 | Aerospike.errorDetailVerbosity.SUBCODE | Subcode |
| 2 | Aerospike.errorDetailVerbosity.MESSAGE | Subcode and message |
| 3 | Aerospike.errorDetailVerbosity.EXP_TRACE | Subcode, message, and expression trace |
AerospikeError.subcodeis the numeric subcode, or0when the server didn’t return one. Dispatch on the(code, subcode)pair, never the subcode alone. Constants are on theaerospike/subcodemodule (Aerospike.subcode.*). See Error subcodes.error.messageincludes the server’s detail text atAerospike.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.