17 #ifndef RCUTILS__ERROR_HANDLING_H_ 18 #define RCUTILS__ERROR_HANDLING_H_ 25 #ifndef __STDC_WANT_LIB_EXT1__ 26 #define __STDC_WANT_LIB_EXT1__ 1 // indicate we would like strnlen_s if available 42 #ifdef __STDC_LIB_EXT1__ 45 #define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) \ 46 do {fwrite(msg, sizeof(char), strnlen_s(msg, 4096), stderr);} while (0) 48 #define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) \ 49 do {fwrite(msg, sizeof(char), strlen(msg), stderr);} while (0) 53 #define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 20 // "18446744073709551615" 54 #define RCUTILS_ERROR_FORMATTING_CHARACTERS 6 // ', at ' + ':' 57 #define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1024 62 #define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH 768 64 #define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH ( \ 65 RCUTILS_ERROR_MESSAGE_MAX_LENGTH - \ 66 RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH - \ 67 RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH - \ 68 RCUTILS_ERROR_FORMATTING_CHARACTERS - \ 90 #if __STDC_VERSION__ >= 201112L 98 "Maximum length calculations incorrect");
169 #define RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type) \ 170 RCUTILS_CHECK_FOR_NULL_WITH_MSG(argument, #argument " argument is null", \ 171 return error_return_type) 182 #define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement) \ 184 if (NULL == value) { \ 185 RCUTILS_SET_ERROR_MSG(msg); \ 200 #define RCUTILS_SET_ERROR_MSG(msg) \ 201 do {rcutils_set_error_state(msg, __FILE__, __LINE__);} while (0) 212 #define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...) \ 214 char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \ 215 int ret = rcutils_snprintf(output_msg, sizeof(output_msg), format_string, __VA_ARGS__); \ 217 RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to call snprintf for error message formatting\n"); \ 219 RCUTILS_SET_ERROR_MSG(output_msg); \ 267 #endif // RCUTILS__ERROR_HANDLING_H_ #define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH
Definition: error_handling.h:53
rcutils_ret_t rcutils_initialize_error_handling_thread_local_storage(rcutils_allocator_t allocator)
Forces initialization of thread-local storage if called in a newly created thread.
uint64_t line_number
Line number of error.
Definition: error_handling.h:86
#define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH
Definition: error_handling.h:64
char str[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]
Definition: error_handling.h:74
struct rcutils_error_state_t rcutils_error_state_t
Struct which encapsulates the error state set by RCUTILS_SET_ERROR_MSG().
void rcutils_reset_error(void)
Reset the error state by clearing any previously set error state.
int rcutils_ret_t
Definition: rcutils_ret.h:23
rcutils_error_string_t rcutils_get_error_string(void)
Return the error message followed by , at <file>:<line> if set, else "error not set".
#define RCUTILS_ERROR_FORMATTING_CHARACTERS
Definition: error_handling.h:54
struct rcutils_error_string_t rcutils_error_string_t
Struct wrapping a fixed-size c string used for returning the formatted error string.
Encapsulation of an allocator.
Definition: allocator.h:45
#define RCUTILS_ERROR_MESSAGE_MAX_LENGTH
Definition: error_handling.h:57
#define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH
Definition: error_handling.h:62
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
#define RCUTILS_PUBLIC
Definition: visibility_control.h:48
const rcutils_error_state_t * rcutils_get_error_state(void)
Return an rcutils_error_state_t which was set with rcutils_set_error_state().
Struct wrapping a fixed-size c string used for returning the formatted error string.
Definition: error_handling.h:72
Struct which encapsulates the error state set by RCUTILS_SET_ERROR_MSG().
Definition: error_handling.h:78
bool rcutils_error_is_set(void)
Return true if the error is set, otherwise false.
void rcutils_set_error_state(const char *error_string, const char *file, size_t line_number)
Set the error message, as well as the file and line on which it occurred.