From eb8809c2e84f2918037da628876eb3198873f710 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Wed, 26 Aug 2020 18:19:30 -0300 Subject: [PATCH 1/3] Add RCUTILS_CAN_SET_ERROR_MSG_AND_RETURN_WITH_ERROR_OF() macro. To fault inject error messages as well as return codes. Signed-off-by: Michel Hidalgo --- include/rcutils/error_handling.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/rcutils/error_handling.h b/include/rcutils/error_handling.h index 940bf06b..52736376 100644 --- a/include/rcutils/error_handling.h +++ b/include/rcutils/error_handling.h @@ -223,6 +223,20 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin } \ } while (0) +/// Indicate that the function intends to set an error message and return an error value. +/** + * \def RCUTILS_CAN_SET_ERROR_MSG_AND_RETURN_WITH_ERROR_OF + * Indicating macro similar to RCUTILS_CAN_RETURN_WITH_ERROR_OF, that also sets an error + * message. + * + * \param error_return_value the value returned as a result of a given error. + */ +#define RCUTILS_CAN_SET_ERROR_MSG_AND_RETURN_WITH_ERROR_OF(error_return_value) \ + RCUTILS_CAN_FAIL_WITH({ \ + RCUTILS_SET_ERROR_MSG("Injecting " RCUTILS_STRINGIFY(error_return_value)); \ + return error_return_value; \ + }) + /// Return `true` if the error is set, otherwise `false`. RCUTILS_PUBLIC RCUTILS_WARN_UNUSED From 37a3a29dae8d90ca6ecdbadf6589de0a0fe5887b Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Thu, 27 Aug 2020 13:00:35 -0300 Subject: [PATCH 2/3] Address peer review comments. Signed-off-by: Michel Hidalgo --- include/rcutils/error_handling.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/rcutils/error_handling.h b/include/rcutils/error_handling.h index 52736376..ca6d64b7 100644 --- a/include/rcutils/error_handling.h +++ b/include/rcutils/error_handling.h @@ -225,13 +225,16 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin /// Indicate that the function intends to set an error message and return an error value. /** - * \def RCUTILS_CAN_SET_ERROR_MSG_AND_RETURN_WITH_ERROR_OF + * \def RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF * Indicating macro similar to RCUTILS_CAN_RETURN_WITH_ERROR_OF, that also sets an error * message. * + * For now, this macro simply relies on `RCUTILS_CAN_FAIL_WITH` to set a generic error + * message and return the given `error_return_value` if fault injection is enabled. + * * \param error_return_value the value returned as a result of a given error. */ -#define RCUTILS_CAN_SET_ERROR_MSG_AND_RETURN_WITH_ERROR_OF(error_return_value) \ +#define RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(error_return_value) \ RCUTILS_CAN_FAIL_WITH({ \ RCUTILS_SET_ERROR_MSG("Injecting " RCUTILS_STRINGIFY(error_return_value)); \ return error_return_value; \ From a8903ed25c2f1c334943326c3796f0bdd86523e3 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Thu, 27 Aug 2020 18:44:33 -0300 Subject: [PATCH 3/3] Please uncrustify. Signed-off-by: Michel Hidalgo --- include/rcutils/error_handling.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/rcutils/error_handling.h b/include/rcutils/error_handling.h index ca6d64b7..6abe168d 100644 --- a/include/rcutils/error_handling.h +++ b/include/rcutils/error_handling.h @@ -235,7 +235,8 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin * \param error_return_value the value returned as a result of a given error. */ #define RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(error_return_value) \ - RCUTILS_CAN_FAIL_WITH({ \ + RCUTILS_CAN_FAIL_WITH( \ + { \ RCUTILS_SET_ERROR_MSG("Injecting " RCUTILS_STRINGIFY(error_return_value)); \ return error_return_value; \ })