Skip to content

Commit

Permalink
Remove codes on the cascading errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Barry Xu <barry.xu@sony.com>
  • Loading branch information
Barry-Xu-2018 committed Oct 10, 2020
1 parent 81fe374 commit e5823e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 82 deletions.
43 changes: 2 additions & 41 deletions rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern "C"
#include "rcl/remap.h"
#include "rcutils/logging_macros.h"
#include "rcutils/macros.h"
#include "rcutils/strdup.h"
#include "rmw/error_handling.h"
#include "rmw/validate_full_topic_name.h"
#include "tracetools/tracetools.h"
Expand Down Expand Up @@ -206,53 +205,15 @@ rcl_publisher_init(
goto cleanup;
fail:
if (publisher->impl) {
// Used for concatenating error messages in the fail: block.
// The cause or error which leads to jump to fail:
char * fail_error_message = NULL;
// The error happens in fail:
char * fini_error_message = NULL;
rcl_allocator_t default_allocator = rcl_get_default_allocator();

if (rcl_error_is_set()) {
fail_error_message = rcutils_strdup(rcl_get_error_string().str, default_allocator);
rcl_reset_error();
}

if (publisher->impl->rmw_handle) {
// If rmw_destroy_publisher fails, it will clobber the error string here.
// Concatenate the error strings if that happens
if (rmw_destroy_publisher(
rcl_node_get_rmw_handle(node),
publisher->impl->rmw_handle) == RMW_RET_ERROR)
publisher->impl->rmw_handle) != RMW_RET_OK)
{
if (rcl_error_is_set()) {
fini_error_message = rcutils_strdup(rcl_get_error_string().str, default_allocator);
rcl_reset_error();
}

RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
"rmw_destroy_publisher failed while handling a previous error."
"\nOriginal error:\n\t%s\nError encountered in rmw_destroy_publisher():\n\t%s\n",
fail_error_message != NULL ?
fail_error_message : "Failed to duplicate error while init publisher !",
fini_error_message != NULL ?
fini_error_message : "Failed to duplicate error while destory rmw publisher !");
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
}
}

if (!rcl_error_is_set()) {
RCL_SET_ERROR_MSG(
(fail_error_message != NULL) ?
fail_error_message : "Unspecified error in rcl_publisher_init() !");
}

if (fail_error_message != NULL) {
default_allocator.deallocate(fail_error_message, default_allocator.state);
}
if (fini_error_message != NULL) {
default_allocator.deallocate(fini_error_message, default_allocator.state);
}

allocator->deallocate(publisher->impl, allocator->state);
publisher->impl = NULL;
}
Expand Down
43 changes: 2 additions & 41 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C"
#include "rcl/expand_topic_name.h"
#include "rcl/remap.h"
#include "rcutils/logging_macros.h"
#include "rcutils/strdup.h"
#include "rmw/error_handling.h"
#include "rmw/validate_full_topic_name.h"
#include "tracetools/tracetools.h"
Expand Down Expand Up @@ -194,53 +193,15 @@ rcl_subscription_init(
goto cleanup;
fail:
if (subscription->impl) {
// Used for concatenating error messages in the fail: block.
// The cause or error which leads to jump to fail:
char * fail_error_message = NULL;
// The error happens in fail:
char * fini_error_message = NULL;
rcl_allocator_t default_allocator = rcl_get_default_allocator();

if (rcl_error_is_set()) {
fail_error_message = rcutils_strdup(rcl_get_error_string().str, default_allocator);
rcl_reset_error();
}

if (subscription->impl->rmw_handle) {
// If rmw_destroy_subscription fails, it will clobber the error string here.
// Concatenate the error strings if that happens
if (rmw_destroy_subscription(
rcl_node_get_rmw_handle(node),
subscription->impl->rmw_handle) == RMW_RET_ERROR)
subscription->impl->rmw_handle) != RMW_RET_OK)
{
if (rcl_error_is_set()) {
fini_error_message = rcutils_strdup(rcl_get_error_string().str, default_allocator);
rcl_reset_error();
}

RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
"rmw_destroy_subscription failed while handling a previous error."
"\nOriginal error:\n\t%s\nError encountered in rmw_destroy_subscription():\n\t%s\n",
fail_error_message != NULL ?
fail_error_message : "Failed to duplicate error while init subscription !",
fini_error_message != NULL ?
fini_error_message : "Failed to duplicate error while destory rmw subscription !");
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
}
}

if (!rcl_error_is_set()) {
RCL_SET_ERROR_MSG(
(fail_error_message != NULL) ?
fail_error_message : "Unspecified error in rcl_subscription_init() !");
}

if (fail_error_message != NULL) {
default_allocator.deallocate(fail_error_message, default_allocator.state);
}
if (fini_error_message != NULL) {
default_allocator.deallocate(fini_error_message, default_allocator.state);
}

allocator->deallocate(subscription->impl, allocator->state);
subscription->impl = NULL;
}
Expand Down

0 comments on commit e5823e8

Please sign in to comment.