Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use new error handling API #153

Merged
merged 2 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include_directories(include)
set(rmw_sources
"src/allocators.c"
"src/convert_rcutils_ret_to_rmw_ret.c"
"src/error_handling.c"
"src/names_and_types.c"
"src/sanity_checks.c"
"src/node_security_options.c"
Expand Down
41 changes: 14 additions & 27 deletions rmw/include/rmw/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,35 @@ extern "C"
{
#endif

#include <stdbool.h>
#include <stddef.h>

#include <rcutils/error_handling.h>

#include "rmw/visibility_control.h"

typedef rcutils_error_string_t rmw_error_string_t;
typedef rcutils_error_state_t rmw_error_state_t;

#define rmw_error_state_copy rcutils_error_state_copy
#define RMW_SAFE_FWRITE_TO_STDERR RCUTILS_SAFE_FWRITE_TO_STDERR

#define rmw_initialize_error_handling_thread_local_storage \
rcutils_initialize_error_handling_thread_local_storage

#define rmw_error_state_fini rcutils_error_state_fini
#define rmw_set_error_state rcutils_set_error_state

// TODO(wjwwood): replace this completely with rcutils_set_error_state()
// once the rmw APIs take an allocator that can be passed
// by the rmw implementations on to the error functions
/// Set the error state, implicitly uses rcutils_get_default_allocator().
/**
* \see rcutils_get_default_allocator()
* \see rcutils_set_error_state()
*/
RMW_PUBLIC
void
rmw_set_error_state(const char * error_msg, const char * file, size_t line_number);
#define RMW_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type) \
RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type)

/// Set the error message, as well as append the current file and line number.
/**
* \see RCUTILS_SET_ERROR_MSG
*/
#define RMW_SET_ERROR_MSG(msg) rmw_set_error_state(msg, __FILE__, __LINE__);
#define RMW_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement) \
RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement)

#define RMW_SET_ERROR_MSG_ALLOC(msg, allocator) \
rcutils_set_error_state(msg, __FILE__, __LINE__, allocator);
#define RMW_SET_ERROR_MSG(msg) RCUTILS_SET_ERROR_MSG(msg)

#define RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...) \
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, __VA_ARGS__)

#define rmw_error_is_set rcutils_error_is_set

#define rmw_get_error_state rcutils_get_error_state

#define rmw_get_error_string rcutils_get_error_string

#define rmw_get_error_string_safe rcutils_get_error_string_safe

#define rmw_reset_error rcutils_reset_error

#ifdef __cplusplus
Expand Down
21 changes: 0 additions & 21 deletions rmw/src/error_handling.c

This file was deleted.

16 changes: 8 additions & 8 deletions rmw/src/names_and_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ rmw_names_and_types_init(
rcutils_allocator_t * allocator)
{
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null")
RMW_SET_ERROR_MSG("allocator is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (!names_and_types) {
RMW_SET_ERROR_MSG_ALLOC("names_and_types is null", *allocator)
RMW_SET_ERROR_MSG("names_and_types is null");
return RMW_RET_INVALID_ARGUMENT;
}
rcutils_ret_t rcutils_ret = rcutils_string_array_init(&names_and_types->names, size, allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
names_and_types->types =
allocator->zero_allocate(size, sizeof(rcutils_string_array_t), allocator->state);
if (!names_and_types->types) {
rcutils_ret = rcutils_string_array_fini(&names_and_types->names);
if (rcutils_ret != RCUTILS_RET_OK) {
RCUTILS_LOG_ERROR("error while reporting error: %s", rcutils_get_error_string_safe());
RCUTILS_LOG_ERROR("error while reporting error: %s", rcutils_get_error_string().str);
}
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for types", *allocator)
RMW_SET_ERROR_MSG("failed to allocate memory for types");
return RMW_RET_BAD_ALLOC;
}
return RMW_RET_OK;
Expand All @@ -89,7 +89,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
return RMW_RET_INVALID_ARGUMENT;
}
if (names_and_types->names.size && !names_and_types->types) {
RMW_SET_ERROR_MSG("invalid names_and_types")
RMW_SET_ERROR_MSG("invalid names_and_types");
return RMW_RET_INVALID_ARGUMENT;
}
rcutils_ret_t rcutils_ret;
Expand All @@ -101,7 +101,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
}
rcutils_ret = rcutils_string_array_fini(&names_and_types->types[i]);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
}
Expand All @@ -115,7 +115,7 @@ rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types)
// Cleanup names string array
rcutils_ret = rcutils_string_array_fini(&names_and_types->names);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
return RMW_RET_OK;
Expand Down