From 32608a259a57b51dbda081f0c51cad39b73d98f9 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 15 Apr 2019 14:30:07 -0400 Subject: [PATCH 01/12] Updated .gitignore Please ignore Signed-off-by: Jacob Hassold --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index e43b0f9889..afdb2434d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .DS_Store + +*.swp + +tags From 59a1c8aca1c7d922b0ee96ecca4844bef06650e6 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 1 Apr 2019 14:48:28 -0400 Subject: [PATCH 02/12] Created function to generate exception objects Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index 84469b5b20..347a703236 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -73,6 +73,40 @@ throw_from_rcl_error( } } + std::exception_ptr + from_rcl_error( + rcl_ret_t ret, + const std::string & prefix, + const rcl_error_state_t * error_state, + void (* reset_error)()) + { + if (RCL_RET_OK == ret) { + return std::make_exception_ptr(std::invalid_argument("ret is RCL_RET_OK")); + } + if (!error_state) { + error_state = rcl_get_error_state(); + } + if (!error_state) { + return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); + } + std::string formated_prefix = prefix; + if (!prefix.empty()) { + formated_prefix += ": "; + } + RCLErrorBase base_exc(ret, error_state); + if (reset_error) { + reset_error(); + } + switch (ret) { + case RCL_RET_BAD_ALLOC: + return std::make_exception_ptr(RCLBadAlloc(base_exc)); + case RCL_RET_INVALID_ARGUMENT: + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formated_prefix)); + default: + return std::make_exception_ptr(RCLError(base_exc, formated_prefix)); + } + } + RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state) : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number), formatted_message(rcl_get_error_string().str) From 4e52689f168cdff27daa9d917d2de16bd4336654 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 1 Apr 2019 14:55:37 -0400 Subject: [PATCH 03/12] Fixed typo Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index 347a703236..eeb09e0276 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -89,9 +89,9 @@ throw_from_rcl_error( if (!error_state) { return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); } - std::string formated_prefix = prefix; + std::string formatted_prefix = prefix; if (!prefix.empty()) { - formated_prefix += ": "; + formatted_prefix += ": "; } RCLErrorBase base_exc(ret, error_state); if (reset_error) { @@ -101,9 +101,9 @@ throw_from_rcl_error( case RCL_RET_BAD_ALLOC: return std::make_exception_ptr(RCLBadAlloc(base_exc)); case RCL_RET_INVALID_ARGUMENT: - return std::make_exception_ptr(RCLInvalidArgument(base_exc, formated_prefix)); + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); default: - return std::make_exception_ptr(RCLError(base_exc, formated_prefix)); + return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); } } From ea06502be3a3ddd239fb403de1e963b78a36c623 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Wed, 3 Apr 2019 10:50:52 -0400 Subject: [PATCH 04/12] Throw exceptions not created by ret Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index eeb09e0276..e681c60593 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -73,39 +73,39 @@ throw_from_rcl_error( } } - std::exception_ptr - from_rcl_error( - rcl_ret_t ret, - const std::string & prefix, - const rcl_error_state_t * error_state, - void (* reset_error)()) - { - if (RCL_RET_OK == ret) { - return std::make_exception_ptr(std::invalid_argument("ret is RCL_RET_OK")); - } - if (!error_state) { - error_state = rcl_get_error_state(); - } - if (!error_state) { - return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); - } - std::string formatted_prefix = prefix; - if (!prefix.empty()) { - formatted_prefix += ": "; - } - RCLErrorBase base_exc(ret, error_state); - if (reset_error) { - reset_error(); - } - switch (ret) { - case RCL_RET_BAD_ALLOC: - return std::make_exception_ptr(RCLBadAlloc(base_exc)); - case RCL_RET_INVALID_ARGUMENT: - return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); - default: - return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); - } +std::exception_ptr +from_rcl_error( + rcl_ret_t ret, + const std::string & prefix, + const rcl_error_state_t * error_state, + void (* reset_error)()) +{ + if (RCL_RET_OK == ret) { + throw std::invalid_argument("ret is RCL_RET_OK"); + } + if (!error_state) { + error_state = rcl_get_error_state(); + } + if (!error_state) { + throw std::runtime_error("rcl error state is not set"); } + std::string formatted_prefix = prefix; + if (!prefix.empty()) { + formatted_prefix += ": "; + } + RCLErrorBase base_exc(ret, error_state); + if (reset_error) { + reset_error(); + } + switch (ret) { + case RCL_RET_BAD_ALLOC: + return std::make_exception_ptr(RCLBadAlloc(base_exc)); + case RCL_RET_INVALID_ARGUMENT: + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); + default: + return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); + } +} RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state) : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number), From 39a3d3e57561b0112195ace98eb2a66d00aaa792 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 1 Apr 2019 14:48:28 -0400 Subject: [PATCH 05/12] Created function to generate exception objects Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index e681c60593..347a703236 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -73,39 +73,39 @@ throw_from_rcl_error( } } -std::exception_ptr -from_rcl_error( - rcl_ret_t ret, - const std::string & prefix, - const rcl_error_state_t * error_state, - void (* reset_error)()) -{ - if (RCL_RET_OK == ret) { - throw std::invalid_argument("ret is RCL_RET_OK"); - } - if (!error_state) { - error_state = rcl_get_error_state(); - } - if (!error_state) { - throw std::runtime_error("rcl error state is not set"); + std::exception_ptr + from_rcl_error( + rcl_ret_t ret, + const std::string & prefix, + const rcl_error_state_t * error_state, + void (* reset_error)()) + { + if (RCL_RET_OK == ret) { + return std::make_exception_ptr(std::invalid_argument("ret is RCL_RET_OK")); + } + if (!error_state) { + error_state = rcl_get_error_state(); + } + if (!error_state) { + return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); + } + std::string formated_prefix = prefix; + if (!prefix.empty()) { + formated_prefix += ": "; + } + RCLErrorBase base_exc(ret, error_state); + if (reset_error) { + reset_error(); + } + switch (ret) { + case RCL_RET_BAD_ALLOC: + return std::make_exception_ptr(RCLBadAlloc(base_exc)); + case RCL_RET_INVALID_ARGUMENT: + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formated_prefix)); + default: + return std::make_exception_ptr(RCLError(base_exc, formated_prefix)); + } } - std::string formatted_prefix = prefix; - if (!prefix.empty()) { - formatted_prefix += ": "; - } - RCLErrorBase base_exc(ret, error_state); - if (reset_error) { - reset_error(); - } - switch (ret) { - case RCL_RET_BAD_ALLOC: - return std::make_exception_ptr(RCLBadAlloc(base_exc)); - case RCL_RET_INVALID_ARGUMENT: - return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); - default: - return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); - } -} RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state) : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number), From 8d538b5fad45fe51d9c28a72e9422fcb4a42db98 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 1 Apr 2019 14:55:37 -0400 Subject: [PATCH 06/12] Fixed typo Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index 347a703236..eeb09e0276 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -89,9 +89,9 @@ throw_from_rcl_error( if (!error_state) { return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); } - std::string formated_prefix = prefix; + std::string formatted_prefix = prefix; if (!prefix.empty()) { - formated_prefix += ": "; + formatted_prefix += ": "; } RCLErrorBase base_exc(ret, error_state); if (reset_error) { @@ -101,9 +101,9 @@ throw_from_rcl_error( case RCL_RET_BAD_ALLOC: return std::make_exception_ptr(RCLBadAlloc(base_exc)); case RCL_RET_INVALID_ARGUMENT: - return std::make_exception_ptr(RCLInvalidArgument(base_exc, formated_prefix)); + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); default: - return std::make_exception_ptr(RCLError(base_exc, formated_prefix)); + return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); } } From 6a04e0394808e0120ab4899a26fe2e6554fabeda Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Wed, 3 Apr 2019 10:50:52 -0400 Subject: [PATCH 07/12] Throw exceptions not created by ret Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index eeb09e0276..e681c60593 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -73,39 +73,39 @@ throw_from_rcl_error( } } - std::exception_ptr - from_rcl_error( - rcl_ret_t ret, - const std::string & prefix, - const rcl_error_state_t * error_state, - void (* reset_error)()) - { - if (RCL_RET_OK == ret) { - return std::make_exception_ptr(std::invalid_argument("ret is RCL_RET_OK")); - } - if (!error_state) { - error_state = rcl_get_error_state(); - } - if (!error_state) { - return std::make_exception_ptr(std::runtime_error("rcl error state is not set")); - } - std::string formatted_prefix = prefix; - if (!prefix.empty()) { - formatted_prefix += ": "; - } - RCLErrorBase base_exc(ret, error_state); - if (reset_error) { - reset_error(); - } - switch (ret) { - case RCL_RET_BAD_ALLOC: - return std::make_exception_ptr(RCLBadAlloc(base_exc)); - case RCL_RET_INVALID_ARGUMENT: - return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); - default: - return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); - } +std::exception_ptr +from_rcl_error( + rcl_ret_t ret, + const std::string & prefix, + const rcl_error_state_t * error_state, + void (* reset_error)()) +{ + if (RCL_RET_OK == ret) { + throw std::invalid_argument("ret is RCL_RET_OK"); + } + if (!error_state) { + error_state = rcl_get_error_state(); + } + if (!error_state) { + throw std::runtime_error("rcl error state is not set"); } + std::string formatted_prefix = prefix; + if (!prefix.empty()) { + formatted_prefix += ": "; + } + RCLErrorBase base_exc(ret, error_state); + if (reset_error) { + reset_error(); + } + switch (ret) { + case RCL_RET_BAD_ALLOC: + return std::make_exception_ptr(RCLBadAlloc(base_exc)); + case RCL_RET_INVALID_ARGUMENT: + return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix)); + default: + return std::make_exception_ptr(RCLError(base_exc, formatted_prefix)); + } +} RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state) : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number), From 8fbf7b291f000efdbef7aa15e3211fd732a9bdf3 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 15 Apr 2019 14:19:41 -0400 Subject: [PATCH 08/12] convert throw_from_rcl_error to use from_rcl_error Mostly just a convenience function Signed-off-by: Jacob Hassold --- .gitignore | 3 +-- rclcpp/src/rclcpp/exceptions.cpp | 30 +++++------------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index afdb2434d0..42ddfef62d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .DS_Store *.swp - -tags +tags \ No newline at end of file diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index e681c60593..5b8e79ea6b 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -46,31 +46,11 @@ throw_from_rcl_error( const rcl_error_state_t * error_state, void (* reset_error)()) { - if (RCL_RET_OK == ret) { - throw std::invalid_argument("ret is RCL_RET_OK"); - } - if (!error_state) { - error_state = rcl_get_error_state(); - } - if (!error_state) { - throw std::runtime_error("rcl error state is not set"); - } - std::string formated_prefix = prefix; - if (!prefix.empty()) { - formated_prefix += ": "; - } - RCLErrorBase base_exc(ret, error_state); - if (reset_error) { - reset_error(); - } - switch (ret) { - case RCL_RET_BAD_ALLOC: - throw RCLBadAlloc(base_exc); - case RCL_RET_INVALID_ARGUMENT: - throw RCLInvalidArgument(base_exc, formated_prefix); - default: - throw RCLError(base_exc, formated_prefix); - } + // We expect this to either throw a standard error, + // or to generate an error pointer (which is caught + // in err, and immediately thrown) + auto err = from_rcl_error(rt, prefix, error_state, reset_error); + std::rethrow_exception(err); } std::exception_ptr From 325ba22cbbba2714adbd19ab6e60c93a5763e255 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Mon, 15 Apr 2019 16:03:50 -0400 Subject: [PATCH 09/12] Re-ordered functions to allow compilation Signed-off-by: Jacob Hassold --- rclcpp/src/rclcpp/exceptions.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rclcpp/src/rclcpp/exceptions.cpp b/rclcpp/src/rclcpp/exceptions.cpp index 5b8e79ea6b..6f5c40f464 100644 --- a/rclcpp/src/rclcpp/exceptions.cpp +++ b/rclcpp/src/rclcpp/exceptions.cpp @@ -39,20 +39,6 @@ NameValidationError::format_error( return msg; } -void -throw_from_rcl_error( - rcl_ret_t ret, - const std::string & prefix, - const rcl_error_state_t * error_state, - void (* reset_error)()) -{ - // We expect this to either throw a standard error, - // or to generate an error pointer (which is caught - // in err, and immediately thrown) - auto err = from_rcl_error(rt, prefix, error_state, reset_error); - std::rethrow_exception(err); -} - std::exception_ptr from_rcl_error( rcl_ret_t ret, @@ -87,6 +73,20 @@ from_rcl_error( } } +void +throw_from_rcl_error( + rcl_ret_t ret, + const std::string & prefix, + const rcl_error_state_t * error_state, + void (* reset_error)()) +{ + // We expect this to either throw a standard error, + // or to generate an error pointer (which is caught + // in err, and immediately thrown) + auto err = from_rcl_error(ret, prefix, error_state, reset_error); + std::rethrow_exception(err); +} + RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state) : ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number), formatted_message(rcl_get_error_string().str) From 04d922b2048f0baa6e7995d3a6ece631e2dc7db1 Mon Sep 17 00:00:00 2001 From: Jacob Hassold Date: Tue, 16 Apr 2019 08:25:55 -0400 Subject: [PATCH 10/12] Revert "Updated .gitignore" This reverts commit bee0ee13ce687bc56bdc7ad1e8382506d9aef428. Signed-off-by: Jacob Hassold --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 42ddfef62d..0000000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.DS_Store - -*.swp -tags \ No newline at end of file From e22ea40e6e3e8cfb15c7878357625fab2b09e38d Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Tue, 16 Apr 2019 09:18:16 -0700 Subject: [PATCH 11/12] restore .gitignore to original state Signed-off-by: Shane Loretz --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..afdb2434d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store + +*.swp + +tags From 7fab2c6bd2c9e5869a15c6e333f72ba652eae574 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Tue, 16 Apr 2019 09:19:55 -0700 Subject: [PATCH 12/12] oops, actually restore .gitignore Signed-off-by: Shane Loretz --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index afdb2434d0..e43b0f9889 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ .DS_Store - -*.swp - -tags