|
esp_iot_framework
v0.1.0-alpha
© 2026 AmakeSasha, distributed under a license Apache-2.0
|
Sequential error handling and parameter validation macros. More...
Macros | |
| #define | EIF_IF_OK_CHECK_NOT_NULL(m_result, m_ptr, m_error) |
| Validates a pointer variable if the current execution state is successful. More... | |
| #define | EIF_IF_OK_CHECK_ESP_ERR_T(m_result, m_expr, m_format, ...) |
| Executes and validates an ESP-IDF expression sequentially. More... | |
| #define | EIF_IF_OK_CHECK_CONDITION(m_ret, m_cond, m_err, m_format, ...) |
| Checks a condition and sets an error status if the condition is true, only when the current status is OK. More... | |
| #define | EIF_IF_OK_CHECK_MBEDTLS_ERR(m_ret, m_expr, func_name) |
| Executes and validates an MbedTLS expression sequentially. More... | |
These macros execute code in chains using a status variable (m_result). If a previous operation failed, subsequent steps are skipped, avoiding deeply nested if-else statements while maintaining strict MISRA C compliance (without goto and return in the middle of the function).
| #define EIF_IF_OK_CHECK_NOT_NULL | ( | m_result, | |
| m_ptr, | |||
| m_error | |||
| ) |
This macro performs a conditional validation check. It verifies whether the provided pointer m_ptr is NULL, but only if m_result currently equals ESP_OK. If the pointer is NULL, the status variable m_result is set to m_error, and it logs a critical error containing the stringified name of the failed parameter. If m_result already contains an error, the check is skipped entirely.
| [in,out] | m_result | Variable holding the active sequence status (esp_err_t). |
| [in] | m_ptr | The pointer identifier or reference to be checked against NULL. |
| [in] | m_error | The custom error status code to assign to m_result if validation fails (type esp_err_t). |
Example of use:
| #define EIF_IF_OK_CHECK_ESP_ERR_T | ( | m_result, | |
| m_expr, | |||
| m_format, | |||
| ... | |||
| ) |
If m_result equals ESP_OK, this macro executes m_expr and writes its return status directly into m_result. On failure (result is not ESP_OK), it extracts the error name via esp_err_to_name() and logs a critical error prefixed with that name. If m_result is already an error state (is not ESP_OK), m_expr is skipped entirely.
| [in,out] | m_result | Status variable (esp_err_t). Checked before execution; overwritten with the return value of m_expr. |
| [in] | m_expr | The function call or expression returning esp_err_t. |
| [in] | m_format | Printf-compliant format string for custom error details. |
| [in] | ... | Optional variadic format arguments matching the format string. |
Example of use:
| #define EIF_IF_OK_CHECK_CONDITION | ( | m_ret, | |
| m_cond, | |||
| m_err, | |||
| m_format, | |||
| ... | |||
| ) |
If m_ret equals ESP_OK, this macro evaluates m_cond. If the condition evaluates to true, it logs a critical error using the provided message (m_info) and sets m_ret to the specified error code (m_err). If m_ret is already in an error state (not ESP_OK), the condition check and logging are skipped entirely.
This macro is useful for validating preconditions (e.g., null checks, range checks) that must be satisfied before proceeding with further operations.
| [in,out] | m_ret | Status variable (esp_err_t). Checked before evaluation; overwritten with m_err if m_cond is true. |
| [in] | m_cond | The condition to evaluate. Must be an expression that can be interpreted as boolean (true/false). |
| [in] | m_err | The error code (esp_err_t) to assign to m_ret if m_cond is true. |
| [in] | m_format | Printf-compliant format string for custom error details. |
| [in] | ... | Optional variadic format arguments matching the format string. |
Example of use:
| #define EIF_IF_OK_CHECK_MBEDTLS_ERR | ( | m_ret, | |
| m_expr, | |||
| func_name | |||
| ) |
CONFIG_EIF_ENABLE_TLS is enabled.This macro operates similarly to EIF_IF_OK_CHECK_ESP_ERR_T, but is specifically designed for the MbedTLS library, which uses int (where 0 is success and negative values are errors) instead of esp_err_t.
If m_ret equals 0, it executes m_expr and stores the result back in m_ret. On failure, it converts the MbedTLS error code into a human-readable string using mbedtls_strerror() and logs it along with the absolute hex value and func_name.
m_ret must be of type int, NOT esp_err_t. Additionally, human-readable error strings require CONFIG_MBEDTLS_ERROR_C to be enabled in the project configuration. Otherwise, mbedtls_strerror might output a generic or empty string.| [in,out] | m_ret | Status variable (int). Checked before execution; overwritten with the return value of m_expr. |
| [in] | m_expr | The MbedTLS function call returning an int. |
| [in] | func_name | String literal representing the operation name (for logging). |
Example of use: