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,
nullwill be returned - On error, the error object is populated.
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. |
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:
| 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 | 3 | 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 at verbosity2.
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.