Skip to content

Commit dd2c47d

Browse files
authored
use new error handling API (#153)
* use new error handling API Signed-off-by: William Woodall <[email protected]> * use semicolons after macros Signed-off-by: William Woodall <[email protected]>
1 parent 3b9ea0f commit dd2c47d

File tree

4 files changed

+22
-57
lines changed

4 files changed

+22
-57
lines changed

rmw/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ include_directories(include)
2727
set(rmw_sources
2828
"src/allocators.c"
2929
"src/convert_rcutils_ret_to_rmw_ret.c"
30-
"src/error_handling.c"
3130
"src/names_and_types.c"
3231
"src/sanity_checks.c"
3332
"src/node_security_options.c"

rmw/include/rmw/error_handling.h

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,35 @@ extern "C"
2020
{
2121
#endif
2222

23-
#include <stdbool.h>
24-
#include <stddef.h>
25-
2623
#include <rcutils/error_handling.h>
2724

28-
#include "rmw/visibility_control.h"
29-
25+
typedef rcutils_error_string_t rmw_error_string_t;
3026
typedef rcutils_error_state_t rmw_error_state_t;
3127

32-
#define rmw_error_state_copy rcutils_error_state_copy
28+
#define RMW_SAFE_FWRITE_TO_STDERR RCUTILS_SAFE_FWRITE_TO_STDERR
29+
30+
#define rmw_initialize_error_handling_thread_local_storage \
31+
rcutils_initialize_error_handling_thread_local_storage
3332

34-
#define rmw_error_state_fini rcutils_error_state_fini
33+
#define rmw_set_error_state rcutils_set_error_state
3534

36-
// TODO(wjwwood): replace this completely with rcutils_set_error_state()
37-
// once the rmw APIs take an allocator that can be passed
38-
// by the rmw implementations on to the error functions
39-
/// Set the error state, implicitly uses rcutils_get_default_allocator().
40-
/**
41-
* \see rcutils_get_default_allocator()
42-
* \see rcutils_set_error_state()
43-
*/
44-
RMW_PUBLIC
45-
void
46-
rmw_set_error_state(const char * error_msg, const char * file, size_t line_number);
35+
#define RMW_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type) \
36+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type)
4737

48-
/// Set the error message, as well as append the current file and line number.
49-
/**
50-
* \see RCUTILS_SET_ERROR_MSG
51-
*/
52-
#define RMW_SET_ERROR_MSG(msg) rmw_set_error_state(msg, __FILE__, __LINE__);
38+
#define RMW_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement) \
39+
RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement)
5340

54-
#define RMW_SET_ERROR_MSG_ALLOC(msg, allocator) \
55-
rcutils_set_error_state(msg, __FILE__, __LINE__, allocator);
41+
#define RMW_SET_ERROR_MSG(msg) RCUTILS_SET_ERROR_MSG(msg)
42+
43+
#define RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...) \
44+
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, __VA_ARGS__)
5645

5746
#define rmw_error_is_set rcutils_error_is_set
5847

5948
#define rmw_get_error_state rcutils_get_error_state
6049

6150
#define rmw_get_error_string rcutils_get_error_string
6251

63-
#define rmw_get_error_string_safe rcutils_get_error_string_safe
64-
6552
#define rmw_reset_error rcutils_reset_error
6653

6754
#ifdef __cplusplus

rmw/src/error_handling.c

Lines changed: 0 additions & 21 deletions
This file was deleted.

rmw/src/names_and_types.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,26 @@ rmw_names_and_types_init(
5656
rcutils_allocator_t * allocator)
5757
{
5858
if (!allocator) {
59-
RMW_SET_ERROR_MSG("allocator is null")
59+
RMW_SET_ERROR_MSG("allocator is null");
6060
return RMW_RET_INVALID_ARGUMENT;
6161
}
6262
if (!names_and_types) {
63-
RMW_SET_ERROR_MSG_ALLOC("names_and_types is null", *allocator)
63+
RMW_SET_ERROR_MSG("names_and_types is null");
6464
return RMW_RET_INVALID_ARGUMENT;
6565
}
6666
rcutils_ret_t rcutils_ret = rcutils_string_array_init(&names_and_types->names, size, allocator);
6767
if (rcutils_ret != RCUTILS_RET_OK) {
68-
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
68+
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
6969
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
7070
}
7171
names_and_types->types =
7272
allocator->zero_allocate(size, sizeof(rcutils_string_array_t), allocator->state);
7373
if (!names_and_types->types) {
7474
rcutils_ret = rcutils_string_array_fini(&names_and_types->names);
7575
if (rcutils_ret != RCUTILS_RET_OK) {
76-
RCUTILS_LOG_ERROR("error while reporting error: %s", rcutils_get_error_string_safe());
76+
RCUTILS_LOG_ERROR("error while reporting error: %s", rcutils_get_error_string().str);
7777
}
78-
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for types", *allocator)
78+
RMW_SET_ERROR_MSG("failed to allocate memory for types");
7979
return RMW_RET_BAD_ALLOC;
8080
}
8181
return RMW_RET_OK;
@@ -89,7 +89,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
8989
return RMW_RET_INVALID_ARGUMENT;
9090
}
9191
if (names_and_types->names.size && !names_and_types->types) {
92-
RMW_SET_ERROR_MSG("invalid names_and_types")
92+
RMW_SET_ERROR_MSG("invalid names_and_types");
9393
return RMW_RET_INVALID_ARGUMENT;
9494
}
9595
rcutils_ret_t rcutils_ret;
@@ -101,7 +101,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
101101
}
102102
rcutils_ret = rcutils_string_array_fini(&names_and_types->types[i]);
103103
if (rcutils_ret != RCUTILS_RET_OK) {
104-
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
104+
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
105105
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
106106
}
107107
}
@@ -115,7 +115,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
115115
// Cleanup names string array
116116
rcutils_ret = rcutils_string_array_fini(&names_and_types->names);
117117
if (rcutils_ret != RCUTILS_RET_OK) {
118-
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
118+
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
119119
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
120120
}
121121
return RMW_RET_OK;

0 commit comments

Comments
 (0)