15 #include "rclcpp/exceptions.hpp"
22 using namespace std::string_literals;
30 NameValidationError::format_error(
31 const char * name_type,
33 const char * error_msg,
37 msg +=
"Invalid "s + name_type +
": " + error_msg +
":\n";
38 msg +=
" '"s + name +
"'\n";
39 msg +=
" "s + std::string(invalid_index,
' ') +
"^\n";
46 const std::string & prefix,
47 const rcl_error_state_t * error_state,
48 void (* reset_error)())
51 throw std::invalid_argument(
"ret is RCL_RET_OK");
54 error_state = rcl_get_error_state();
57 throw std::runtime_error(
"rcl error state is not set");
59 std::string formatted_prefix = prefix;
60 if (!prefix.empty()) {
61 formatted_prefix +=
": ";
63 RCLErrorBase base_exc(ret, error_state);
69 return std::make_exception_ptr(RCLBadAlloc(base_exc));
71 return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix));
73 return std::make_exception_ptr(RCLInvalidROSArgsError(base_exc, formatted_prefix));
75 return std::make_exception_ptr(RCLError(base_exc, formatted_prefix));
82 const std::string & prefix,
83 const rcl_error_state_t * error_state,
84 void (* reset_error)())
89 auto err = from_rcl_error(ret, prefix, error_state, reset_error);
90 std::rethrow_exception(err);
93 RCLErrorBase::RCLErrorBase(
rcl_ret_t ret,
const rcl_error_state_t * error_state)
94 : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number),
95 formatted_message(rcl_get_error_string().str)
100 const rcl_error_state_t * error_state,
101 const std::string & prefix)
102 : RCLError(RCLErrorBase(ret, error_state), prefix)
106 const RCLErrorBase & base_exc,
107 const std::string & prefix)
108 : RCLErrorBase(base_exc), std::runtime_error(prefix + base_exc.formatted_message)
111 RCLBadAlloc::RCLBadAlloc(
rcl_ret_t ret,
const rcl_error_state_t * error_state)
112 : RCLBadAlloc(RCLErrorBase(ret, error_state))
115 RCLBadAlloc::RCLBadAlloc(
const RCLErrorBase & base_exc)
116 : RCLErrorBase(base_exc), std::bad_alloc()
119 RCLInvalidArgument::RCLInvalidArgument(
121 const rcl_error_state_t * error_state,
122 const std::string & prefix)
123 : RCLInvalidArgument(RCLErrorBase(ret, error_state), prefix)
126 RCLInvalidArgument::RCLInvalidArgument(
127 const RCLErrorBase & base_exc,
128 const std::string & prefix)
129 : RCLErrorBase(base_exc), std::invalid_argument(prefix + base_exc.formatted_message)
132 RCLInvalidROSArgsError::RCLInvalidROSArgsError(
134 const rcl_error_state_t * error_state,
135 const std::string & prefix)
136 : RCLInvalidROSArgsError(RCLErrorBase(ret, error_state), prefix)
139 RCLInvalidROSArgsError::RCLInvalidROSArgsError(
140 const RCLErrorBase & base_exc,
141 const std::string & prefix)
142 : RCLErrorBase(base_exc), std::runtime_error(prefix + base_exc.formatted_message)
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
#define RCL_RET_INVALID_ROS_ARGS
Found invalid ros argument while parsing.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.