Skip to content

Commit 981013a

Browse files
authored
feat: Add ESP_RETURN_ON_ERR macro
1 parent a6c3a9c commit 981013a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/esp_common/include/esp_err.h

+12
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ void _esp_error_check_failed_without_abort(esp_err_t rc, const char *file, int l
9292
#endif
9393
/** @endcond */
9494

95+
/**
96+
* Macro that returns the error code if an error occurs, optionally running extra code.
97+
* The extra code can be placed after the function thay may error and it will only run if the error occurs.
98+
*/
99+
#define ESP_RETURN_ON_ERR(x, ...) do { \
100+
esp_err_t err_rc_ = (x); \
101+
if (unlikely(err_rc_ != ESP_OK)) { \
102+
__VA_ARGS__; \
103+
return err_rc_; \
104+
} \
105+
} while (0)
106+
95107
/**
96108
* Macro which can be used to check the error code,
97109
* and terminate the program in case the code is not ESP_OK.

0 commit comments

Comments
 (0)