Skip to content

Commit 9566f39

Browse files
author
Siddharth Kucheria
authored
rcl_action - user friendly error messages for invalid transitions (#448)
* user friendly error messages for invalid transitions Signed-off-by: Siddharth Kucheria <[email protected]>
1 parent 0736f93 commit 9566f39

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

rcl_action/include/rcl_action/types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ typedef int8_t rcl_action_goal_state_t;
9393
#define GOAL_STATE_ABORTED action_msgs__msg__GoalStatus__STATUS_ABORTED
9494
#define GOAL_STATE_NUM_STATES 7
9595

96+
/// User friendly error messages for invalid trasntions
97+
// Description variables in types.c should be changed if enum values change
98+
extern const char * goal_state_descriptions[];
99+
extern const char * goal_event_descriptions[];
100+
96101
/// Goal state transition events
97102
typedef enum rcl_action_goal_event_t
98103
{

rcl_action/src/rcl_action/goal_handle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ rcl_action_update_goal_state(
8989
goal_handle->impl->state, goal_event);
9090
if (GOAL_STATE_UNKNOWN == new_state) {
9191
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
92-
"goal_handle attempted invalid transition from state %d with event %d",
93-
goal_handle->impl->state,
94-
goal_event);
92+
"goal_handle attempted invalid transition from state %s with event %s",
93+
goal_state_descriptions[goal_handle->impl->state],
94+
goal_event_descriptions[goal_event]);
9595
return RCL_RET_ACTION_GOAL_EVENT_INVALID;
9696
}
9797
goal_handle->impl->state = new_state;

rcl_action/src/rcl_action/types.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ rcl_action_cancel_response_fini(rcl_action_cancel_response_t * cancel_response)
132132
return RCL_RET_OK;
133133
}
134134

135+
/// Values should be changed if enum values change
136+
const char * goal_state_descriptions[] =
137+
{"UNKNOWN", "ACCEPTED", "EXECUTING", "CANCELING", "SUCCEEDED", "CANCELED", "ABORTED"};
138+
139+
const char * goal_event_descriptions[] =
140+
{"EXECUTE", "CANCEL_GOAL", "SUCCEED", "ABORT", "CANCELED", "NUM_EVENTS"};
141+
135142
#ifdef __cplusplus
136143
}
137144
#endif

0 commit comments

Comments
 (0)