From 96458bf36c7a6bf6e7efc8e3e2c09aa514de87ae Mon Sep 17 00:00:00 2001 From: bvonhall Date: Tue, 12 May 2020 13:45:01 +0200 Subject: [PATCH 1/5] O2-1416 Better string representation of the ObjectNotFoundException --- CMakeLists.txt | 1 + include/Common/Exceptions.h | 5 +++- test/testExceptions.cxx | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/testExceptions.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fc01ca..a3f2236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,7 @@ set(TEST_SRCS test/TestSystem.cxx test/testMemPool.cxx test/testTimer.cxx + test/testExceptions.cxx ) foreach (test ${TEST_SRCS}) diff --git a/include/Common/Exceptions.h b/include/Common/Exceptions.h index ab2922f..463d091 100644 --- a/include/Common/Exceptions.h +++ b/include/Common/Exceptions.h @@ -29,7 +29,10 @@ struct ObjectNotFoundError : virtual ExceptionBase { const char *what() const noexcept override { - return "Object not found error"; + std::string message = "Object not found: "; + auto* errinfo = boost::get_error_info(*this); + message += errinfo ? *boost::get_error_info(*this) : "(object_name not specified)"; + return strdup(message.c_str()); } }; diff --git a/test/testExceptions.cxx b/test/testExceptions.cxx new file mode 100644 index 0000000..46e3aa5 --- /dev/null +++ b/test/testExceptions.cxx @@ -0,0 +1,50 @@ +#include "../include/Common/Exceptions.h" + +#define BOOST_TEST_MODULE Exceptions test +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include +#include +#include +#include + +#include + +using namespace std; +using namespace AliceO2::Common; +using boost::test_tools::output_test_stream; + +void foo() +{ + BOOST_THROW_EXCEPTION(ObjectNotFoundError() << errinfo_object_name("object1")); +} + +void bar() +{ + BOOST_THROW_EXCEPTION(ObjectNotFoundError()); +} + +BOOST_AUTO_TEST_CASE(exceptions_test) +{ + BOOST_CHECK_THROW(foo(), ObjectNotFoundError); + + try { + foo(); + } catch (ObjectNotFoundError& e) { + cout << e.what() << endl; + output_test_stream output; + output << e.what(); + BOOST_TEST( !output.is_empty( false ) ); + BOOST_TEST( output.is_equal( "Object not found: object1" ) ); + } + + try { + bar(); + } catch (ObjectNotFoundError& e) { + cout << e.what() << endl; + output_test_stream output; + output << e.what(); + BOOST_TEST( !output.is_empty( false ) ); + BOOST_TEST( output.is_equal( "Object not found: (object_name not specified)" ) ); + } +} From f299a3c846a4a799afa5c14e0df352b24a8d723c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 12 May 2020 15:33:12 +0200 Subject: [PATCH 2/5] Update testExceptions.cxx --- test/testExceptions.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testExceptions.cxx b/test/testExceptions.cxx index 46e3aa5..0318dfb 100644 --- a/test/testExceptions.cxx +++ b/test/testExceptions.cxx @@ -7,7 +7,7 @@ #include #include #include - +#include #include using namespace std; From a051ac82aa6990b31010af86d685d4026313c48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 12 May 2020 15:33:56 +0200 Subject: [PATCH 3/5] Update testExceptions.cxx --- test/testExceptions.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testExceptions.cxx b/test/testExceptions.cxx index 0318dfb..068b5a3 100644 --- a/test/testExceptions.cxx +++ b/test/testExceptions.cxx @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(exceptions_test) cout << e.what() << endl; output_test_stream output; output << e.what(); - BOOST_TEST( !output.is_empty( false ) ); - BOOST_TEST( output.is_equal( "Object not found: (object_name not specified)" ) ); + BOOST_TEST(!output.is_empty(false)); + BOOST_TEST(output.is_equal("Object not found: (object_name not specified)")); } } From e3b55211b91fa0a6c013b7d9e009d5abe0a05d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 12 May 2020 16:01:37 +0200 Subject: [PATCH 4/5] Update testExceptions.cxx --- test/testExceptions.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testExceptions.cxx b/test/testExceptions.cxx index 068b5a3..d1533d8 100644 --- a/test/testExceptions.cxx +++ b/test/testExceptions.cxx @@ -34,8 +34,8 @@ BOOST_AUTO_TEST_CASE(exceptions_test) cout << e.what() << endl; output_test_stream output; output << e.what(); - BOOST_TEST( !output.is_empty( false ) ); - BOOST_TEST( output.is_equal( "Object not found: object1" ) ); + BOOST_CHECK( !output.is_empty( false ) ); + BOOST_CHECK( output.is_equal( "Object not found: object1" ) ); } try { @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(exceptions_test) cout << e.what() << endl; output_test_stream output; output << e.what(); - BOOST_TEST(!output.is_empty(false)); - BOOST_TEST(output.is_equal("Object not found: (object_name not specified)")); + BOOST_CHECK(!output.is_empty(false)); + BOOST_CHECK(output.is_equal("Object not found: (object_name not specified)")); } } From e5e0531db12feeb2bde86dc22809df9b192c2136 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 7 Feb 2025 14:03:04 +0100 Subject: [PATCH 5/5] Force CI rerun