Error handling
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
On error, the Aerospike Python client raises an AerospikeError exception or one of its subclasses. The exception includes the following attributes:
| Attribute | Description |
|---|---|
code | The error code that identifies the error. See as_status.h of the Aerospike C client for error code descriptions. |
msg | The error message with details. |
file | The file where the error occurred. |
line | The line number in the file where the error occurred. |
Exception Handling
To handle the exceptions, wrap the code in a try-except block:
from __future__ import print_function
import aerospikefrom aerospike.exception import *
try: config = { 'hosts': [ ('127.0.0.1', 3000)], 'policies': { 'timeout': 1200}} client = aerospike.client(config) client.close()except ClientError as e: print("Error: {0} [{1}]".format(e.msg, e.code))Server error details
Aerospike Database 8.2.0 can return a numeric subcode and a message on failed operations. Enable this by setting error_detail_verbosity in the policy dict passed to the operation, then read the subcode from the exception:
import aerospike
policy = {"error_detail_verbosity": aerospike.ERROR_DETAIL_SUBCODE}
try: (key, meta, bins) = client.get(key, policy)except aerospike.exception.AerospikeError as e: print(f"status={e.code} subcode={e.subcode} message={e.msg}")Verbosity levels are named constants on the aerospike module:
| Value | Constant | Server returns |
|---|---|---|
| 0 | aerospike.ERROR_DETAIL_NONE | Top-level status only (default) |
| 1 | aerospike.ERROR_DETAIL_SUBCODE | Subcode |
| 2 | aerospike.ERROR_DETAIL_MESSAGE | Subcode and message |
| 3 | 3 | Subcode, message, and expression trace |
AerospikeError.subcodeis the numeric subcode, oraerospike.SUB_NONEwhen the server didn’t return one. Dispatch on the(code, subcode)pair, never the subcode alone. Constants areaerospike.SUB_*(for exampleaerospike.SUB_FORBID_TRUNCATED). See Error subcodes.AerospikeError.msgincludes the server’s detail text at verbosity2.
The Python client does not decode the verbosity-3 expression trace into a data structure, but it does return a string of the expression trace in the msg 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 Python client version that pairs with Database 8.2.0.