-
Notifications
You must be signed in to change notification settings - Fork 164
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
Improve error messages in rcl_lifecycle #742
Changes from all commits
a7a495b
6456f9f
7165b8e
07b4e72
fd58e88
2bc301e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,25 +53,19 @@ rcl_lifecycle_state_init( | |
const char * label, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't initialize state, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
if (!state) { | ||
RCL_SET_ERROR_MSG("state pointer is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
if (!label) { | ||
RCL_SET_ERROR_MSG("State label is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't initialize state, no allocator given\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state, "state pointer is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
label, "State label is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
state->id = id; | ||
state->label = rcutils_strndup(label, strlen(label), *allocator); | ||
if (!state->label) { | ||
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_state_t\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state->label, "failed to duplicate label for rcl_lifecycle_state_t\n", return RCL_RET_ERROR); | ||
|
||
return RCL_RET_OK; | ||
} | ||
|
@@ -81,12 +75,10 @@ rcl_lifecycle_state_fini( | |
rcl_lifecycle_state_t * state, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_ERROR); | ||
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT); | ||
|
||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't free state, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't free state, no allocator given\n", return RCL_RET_INVALID_ARGUMENT); | ||
// it is already NULL | ||
if (!state) { | ||
return RCL_RET_OK; | ||
|
@@ -120,30 +112,24 @@ rcl_lifecycle_transition_init( | |
rcl_lifecycle_state_t * goal, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't initialize transition, no allocator given\n", | ||
return RCL_RET_INVALID_ARGUMENT); | ||
|
||
if (!transition) { | ||
RCL_SET_ERROR_MSG("transition pointer is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
transition, "transition pointer is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
if (!label) { | ||
RCL_SET_ERROR_MSG("label pointer is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
label, "label pointer is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
transition->start = start; | ||
transition->goal = goal; | ||
|
||
transition->id = id; | ||
transition->label = rcutils_strndup(label, strlen(label), *allocator); | ||
if (!transition->label) { | ||
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_transition_t\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
transition->label, "failed to duplicate label for rcl_lifecycle_transition_t\n", | ||
return RCL_RET_ERROR); | ||
|
||
return RCL_RET_OK; | ||
} | ||
|
@@ -153,10 +139,8 @@ rcl_lifecycle_transition_fini( | |
rcl_lifecycle_transition_t * transition, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't finalize transition, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't finalize transition, no allocator given\n", return RCL_RET_INVALID_ARGUMENT); | ||
// it is already NULL | ||
if (!transition) { | ||
return RCL_RET_OK; | ||
|
@@ -206,18 +190,15 @@ rcl_lifecycle_state_machine_init( | |
bool default_states, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
if (!state_machine) { | ||
RCL_SET_ERROR_MSG("State machine is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
if (!node_handle) { | ||
RCL_SET_ERROR_MSG("Node handle is null\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't initialize state machine, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state_machine, "State machine is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
node_handle, "Node handle is null\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't initialize state machine, no allocator given\n", | ||
return RCL_RET_INVALID_ARGUMENT); | ||
|
||
rcl_ret_t ret = rcl_lifecycle_com_interface_init( | ||
&state_machine->com_interface, node_handle, | ||
|
@@ -247,10 +228,8 @@ rcl_lifecycle_state_machine_fini( | |
rcl_node_t * node_handle, | ||
const rcl_allocator_t * allocator) | ||
{ | ||
if (!allocator) { | ||
RCL_SET_ERROR_MSG("can't free state machine, no allocator given\n"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_ALLOCATOR_WITH_MSG( | ||
allocator, "can't free state machine, no allocator given\n", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
rcl_ret_t fcn_ret = RCL_RET_OK; | ||
|
||
|
@@ -278,17 +257,17 @@ rcl_lifecycle_state_machine_fini( | |
rcl_ret_t | ||
rcl_lifecycle_state_machine_is_initialized(const rcl_lifecycle_state_machine_t * state_machine) | ||
{ | ||
if (!state_machine->com_interface.srv_get_state.impl) { | ||
RCL_SET_ERROR_MSG("get_state service is null"); | ||
return RCL_RET_ERROR; | ||
} | ||
if (!state_machine->com_interface.srv_change_state.impl) { | ||
RCL_SET_ERROR_MSG("change_state service is null"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state_machine->com_interface.srv_get_state.impl, "get_state service is null\n", | ||
return RCL_RET_INVALID_ARGUMENT); | ||
|
||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state_machine->com_interface.srv_change_state.impl, "change_state service is null\n", | ||
return RCL_RET_INVALID_ARGUMENT); | ||
|
||
if (rcl_lifecycle_transition_map_is_initialized(&state_machine->transition_map) != RCL_RET_OK) { | ||
RCL_SET_ERROR_MSG("transition map is null"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing to set error message. I think that it would be better to be independent bug fix only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
do you mean revert this part code and make a new commit only for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fujitatomoya There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry my memory is little hazy, but what i meant is replace RCL_SET_ERROR_MSG into RCL_CHECK_FOR_NULL_WITH_MSG, also related to https://github.com/ros2/rcl/pull/742/files#r471208047 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it came back! previously "transition map is null" error message is deleted, i was thinking that it would be better to keep the error message to be set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had updated the code to revert it back. |
||
return RCL_RET_ERROR; | ||
return RCL_RET_INVALID_ARGUMENT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just return the error from rcl_lifecycle_transition_map_is_initialized instead? What about the following?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with you, updated! |
||
} | ||
return RCL_RET_OK; | ||
} | ||
|
@@ -342,16 +321,11 @@ _trigger_transition( | |
bool publish_notification) | ||
{ | ||
// If we have a faulty transition pointer | ||
if (!transition) { | ||
RCL_SET_ERROR_MSG("Transition is not registered."); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
transition, "Transition is not registered.", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
if (!transition->goal) { | ||
RCUTILS_LOG_ERROR_NAMED( | ||
ROS_PACKAGE_NAME, "No valid goal is set"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
transition->goal, "No valid goal is set.", return RCL_RET_INVALID_ARGUMENT); | ||
state_machine->current_state = transition->goal; | ||
|
||
if (publish_notification) { | ||
|
@@ -374,10 +348,8 @@ rcl_lifecycle_trigger_transition_by_id( | |
uint8_t id, | ||
bool publish_notification) | ||
{ | ||
if (!state_machine) { | ||
RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "state machine pointer is null"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state_machine, "state machine pointer is null.", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
const rcl_lifecycle_transition_t * transition = | ||
rcl_lifecycle_get_transition_by_id(state_machine->current_state, id); | ||
|
@@ -391,10 +363,8 @@ rcl_lifecycle_trigger_transition_by_label( | |
const char * label, | ||
bool publish_notification) | ||
{ | ||
if (!state_machine) { | ||
RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "state machine pointer is null"); | ||
return RCL_RET_ERROR; | ||
} | ||
RCL_CHECK_FOR_NULL_WITH_MSG( | ||
state_machine, "state machine pointer is null.", return RCL_RET_INVALID_ARGUMENT); | ||
|
||
const rcl_lifecycle_transition_t * transition = | ||
rcl_lifecycle_get_transition_by_label(state_machine->current_state, label); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we also need to update header file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!