Error Code Reference¶
This page documents all error codes used throughout the Nexus platform.
All HAL and framework functions return nx_status_t to indicate success or failure.
Error Code Categories¶
Error codes are organized into categories for easy identification:
0: Success
1-19: General errors
20-39: State errors
40-59: Resource errors
60-79: Timeout errors
80-99: IO errors
100-119: DMA errors
120-139: Data errors
140-159: Permission errors
Success Code¶
Code |
Value |
Description |
|---|---|---|
|
0 |
Operation completed successfully |
General Errors (1-19)¶
Code |
Value |
Description |
|---|---|---|
|
1 |
Generic error (use more specific codes when possible) |
|
2 |
Invalid parameter passed to function |
|
3 |
Null pointer passed where valid pointer required |
|
4 |
Operation not supported by this device/platform |
|
5 |
Requested item not found |
|
6 |
Invalid size parameter |
State Errors (20-39)¶
Code |
Value |
Description |
|---|---|---|
|
20 |
Device or module not initialized |
|
21 |
Device or module already initialized |
|
22 |
Operation invalid in current state |
|
23 |
Device is busy with another operation |
|
24 |
Device is in suspended state |
Resource Errors (40-59)¶
Code |
Value |
Description |
|---|---|---|
|
40 |
Out of memory |
|
41 |
Required resource unavailable |
|
42 |
Resource is busy |
|
43 |
Resource is locked |
|
44 |
Buffer or queue is full |
|
45 |
Buffer or queue is empty |
Timeout Errors (60-79)¶
Code |
Value |
Description |
|---|---|---|
|
60 |
Operation timed out |
|
61 |
Operation would block (non-blocking mode) |
IO Errors (80-99)¶
Code |
Value |
Description |
|---|---|---|
|
80 |
Generic IO error |
|
81 |
Buffer overrun occurred |
|
82 |
Buffer underrun occurred |
|
83 |
Parity error detected |
|
84 |
Framing error detected |
|
85 |
Noise error detected |
|
86 |
NACK received (I2C communication) |
|
87 |
Bus error occurred |
|
88 |
Arbitration lost (I2C/CAN) |
DMA Errors (100-119)¶
Code |
Value |
Description |
|---|---|---|
|
100 |
Generic DMA error |
|
101 |
DMA transfer error |
|
102 |
DMA configuration error |
Data Errors (120-139)¶
Code |
Value |
Description |
|---|---|---|
|
120 |
No data available |
|
121 |
Data size error |
|
122 |
CRC check failed |
|
123 |
Checksum verification failed |
Permission Errors (140-159)¶
Code |
Value |
Description |
|---|---|---|
|
140 |
Permission denied |
|
141 |
Attempted write to read-only resource |
Error Handling Utilities¶
Checking Status¶
#include "hal/nx_status.h"
nx_status_t status = some_function();
/* Check if operation succeeded */
if (NX_IS_OK(status)) {
/* Success */
}
/* Check if operation failed */
if (NX_IS_ERROR(status)) {
/* Handle error */
}
Error Propagation¶
#include "hal/nx_status.h"
nx_status_t my_function(void) {
nx_status_t status;
/* Return immediately if error occurs */
status = some_operation();
NX_RETURN_IF_ERROR(status);
/* Check for NULL pointer */
void* ptr = get_pointer();
NX_RETURN_IF_NULL(ptr);
/* Continue with normal flow */
return NX_OK;
}
Error Cleanup¶
#include "hal/nx_status.h"
nx_status_t my_function(void) {
nx_status_t result = NX_OK;
void* resource = NULL;
/* Allocate resource */
resource = allocate();
if (!resource) {
result = NX_ERR_NO_MEMORY;
goto cleanup;
}
/* Use resource */
NX_GOTO_IF_ERROR(operation(resource), cleanup, result);
cleanup:
if (resource) {
free(resource);
}
return result;
}
Error Callbacks¶
#include "hal/nx_status.h"
/* Error callback function */
void error_handler(void* user_data, nx_status_t status,
const char* module, const char* msg) {
/* Log error */
LOG_ERROR(module, "Error %d: %s", status, msg);
}
/* Register error callback */
nx_set_error_callback(error_handler, NULL);
/* Errors will now be reported through callback */
Converting to String¶
#include "hal/nx_status.h"
nx_status_t status = some_function();
if (NX_IS_ERROR(status)) {
const char* error_str = nx_status_to_string(status);
printf("Error: %s\n", error_str);
}
Best Practices¶
Always check return values: Never ignore status codes from HAL functions
Use specific error codes: Prefer specific codes over
NX_ERR_GENERICPropagate errors: Use
NX_RETURN_IF_ERRORto propagate errors up the call stackClean up resources: Use
NX_GOTO_IF_ERRORfor proper cleanup on errorLog errors: Use error callbacks or logging to track errors in production
Document error conditions: Document which errors each function can return
Common Error Scenarios¶
Initialization Errors¶
/* Device not initialized */
status = device_operation();
if (status == NX_ERR_NOT_INIT) {
/* Initialize device first */
device_init();
}
Timeout Handling¶
/* Operation with timeout */
status = device_read(buffer, size, 1000);
if (status == NX_ERR_TIMEOUT) {
/* Retry or handle timeout */
}
Resource Management¶
/* Check for resource availability */
status = allocate_resource();
if (status == NX_ERR_NO_MEMORY) {
/* Free some memory and retry */
}
Communication Errors¶
/* I2C communication */
status = i2c_write(addr, data, len);
if (status == NX_ERR_NACK) {
/* Device not responding */
} else if (status == NX_ERR_ARBITRATION) {
/* Bus arbitration lost, retry */
}
See Also¶
HAL API Reference - HAL API Reference
Hardware Abstraction Layer (HAL) - HAL User Guide
Coding Standards - Coding Standards