diff --git a/src/core/include/openvino/core/except.hpp b/src/core/include/openvino/core/except.hpp index a10e6c76f42..0505231027c 100644 --- a/src/core/include/openvino/core/except.hpp +++ b/src/core/include/openvino/core/except.hpp @@ -13,6 +13,12 @@ namespace ov { +struct CheckLocInfo { + const char* file; + int line; + const char* check_string; +}; + /// Base error for ov runtime errors. class OPENVINO_API Exception : public std::runtime_error { public: @@ -20,6 +26,12 @@ public: explicit Exception(const std::string& what_arg); [[noreturn]] static void create(const char* file, int line, const std::string& explanation); + + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + explanation); virtual ~Exception(); static const std::string default_msg; @@ -64,6 +76,14 @@ public: const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + protected: OPENVINO_SUPPRESS_DEPRECATED_START explicit AssertFailure(const std::string& what_arg) : ov::Exception(what_arg) {} @@ -75,6 +95,14 @@ class OPENVINO_API NotImplemented : public AssertFailure { public: [[noreturn]] static void create(const char* file, int line, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + [[noreturn]] OPENVINO_DEPRECATED( "This function is deprecated and will be removed, please use " "OPENVINO_THROW_NOT_IMPLEMENTED instead") static void create(const char* file, diff --git a/src/core/include/openvino/core/node.hpp b/src/core/include/openvino/core/node.hpp index 68910bf70b8..4439cedc397 100644 --- a/src/core/include/openvino/core/node.hpp +++ b/src/core/include/openvino/core/node.hpp @@ -534,6 +534,20 @@ public: std::pair*>&& ctx, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const Node* node, + const std::string& + explanation); + + template + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 " + "release") static void create(const CheckLocInfo& check_loc_info, + std::pair*>&& ctx, + const std::string& explanation); + protected: explicit NodeValidationFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} }; @@ -552,6 +566,12 @@ OPENVINO_API void NodeValidationFailure::create(const char* file, const char* check_string, std::pair*>&& ctx, const std::string& explanation); + +template <> +OPENVINO_API void NodeValidationFailure::create(const CheckLocInfo& check_loc_info, + std::pair*>&& ctx, + const std::string& explanation); + } // namespace ov #define NODE_VALIDATION_CHECK(node, ...) OPENVINO_ASSERT_HELPER(::ov::NodeValidationFailure, (node), __VA_ARGS__) diff --git a/src/core/src/except.cpp b/src/core/src/except.cpp index dcdc08e7661..47e666e3950 100644 --- a/src/core/src/except.cpp +++ b/src/core/src/except.cpp @@ -14,6 +14,10 @@ void ov::Exception::create(const char* file, int line, const std::string& explan OPENVINO_SUPPRESS_DEPRECATED_END } +void ov::Exception::create(const CheckLocInfo& check_loc_info, const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, explanation); +} + std::string ov::Exception::make_what(const char* file, int line, const char* check_string, @@ -47,10 +51,22 @@ void ov::AssertFailure::create(const char* file, throw ov::AssertFailure(make_what(file, line, check_string, context_info, explanation)); } +void ov::AssertFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +} + void ov::NotImplemented::create(const char* file, int line, const std::string& explanation) { throw ov::NotImplemented(make_what(file, line, nullptr, default_msg, explanation)); } +void ov::NotImplemented::create(const CheckLocInfo& check_loc_info, + const std::string&, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, explanation); +} + void ov::NotImplemented::create(const char* file, int line, const char*, diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index bbda9887704..1a87d89fe4d 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -28,6 +28,12 @@ static const char idx_txt[] = "index '"; static const char out_of_range_txt[] = "' out of range"; } // namespace +void ov::NodeValidationFailure::create(const CheckLocInfo& check_loc_info, + const Node* node, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, node, explanation); +} + void ov::NodeValidationFailure::create(const char* file, int line, const char* check_string, @@ -50,6 +56,13 @@ void ov::NodeValidationFailure::create(const char* file, op::validate::shape_infer_explanation_str(*ctx.second, explanation))); } +template <> +void ov::NodeValidationFailure::create(const CheckLocInfo& check_loc_info, + std::pair*>&& ctx, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, std::move(ctx), explanation); +} + atomic ov::Node::m_next_instance_id(0); ov::Node::Node() = default; diff --git a/src/core/tests/check.cpp b/src/core/tests/check.cpp index 69a0f1342ff..be5b6040288 100644 --- a/src/core/tests/check.cpp +++ b/src/core/tests/check.cpp @@ -61,3 +61,53 @@ TEST(check, ov_throw_exception_check_relative_path_to_source) { ov::Exception, AnyOf(StartsWith(exp_native_slash), StartsWith(exp_fwd_slash))); } + +TEST(check, create_ov_exception) { + constexpr int line = 145; + constexpr char test_file[] = "src/test_file.cpp"; + const std::string explanation = "test error message"; + const std::string exp_error_msg = "Exception from src/test_file.cpp:145:\ntest error message\n"; + + OV_EXPECT_THROW(ov::Exception::create(test_file, line, explanation), ov::Exception, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(ov::Exception::create({test_file, line, nullptr}, explanation), ov::Exception, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(check, create_ov_assert_failure) { + constexpr int line = 145; + constexpr char test_file[] = "src/test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string explanation = "test error message"; + const std::string ctx_info = "My context"; + const std::string exp_error_msg = + "Check 'value != 0' failed at src/test_file.cpp:145:\nMy context:\ntest error message\n"; + + OV_EXPECT_THROW(ov::AssertFailure::create(test_file, line, check_string, ctx_info, explanation), + ov::AssertFailure, + exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(ov::AssertFailure::create({test_file, line, check_string}, ctx_info, explanation), + ov::AssertFailure, + exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(check, create_ov_not_implemented) { + constexpr int line = 145; + constexpr char test_file[] = "src/test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string explanation = "test error message"; + const std::string ctx_info = "My context"; + const std::string exp_error_msg = "Exception from src/test_file.cpp:145:\nNot Implemented:\ntest error message\n"; + + OV_EXPECT_THROW(ov::NotImplemented::create(test_file, line, explanation), ov::NotImplemented, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(ov::NotImplemented::create({test_file, line, check_string}, ctx_info, explanation), + ov::NotImplemented, + exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} diff --git a/src/core/tests/frontend/frontend_manager.cpp b/src/core/tests/frontend/frontend_manager.cpp index 1e62a2a39e3..0ecc71fde8c 100644 --- a/src/core/tests/frontend/frontend_manager.cpp +++ b/src/core/tests/frontend/frontend_manager.cpp @@ -8,6 +8,7 @@ #include #include "common_test_utils/file_utils.hpp" +#include "common_test_utils/test_assertions.hpp" #include "openvino/frontend/exception.hpp" #include "openvino/frontend/manager.hpp" #include "openvino/util/file_util.hpp" @@ -307,6 +308,81 @@ TEST(FrontEndExceptionTest, frontend_initialization_error_throw_info) { FAIL() << "Test is expected to throw an exception."; } +TEST(FrontEndExceptionTest, create_general_error) { + constexpr int line = 341; + constexpr char test_file[] = "test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string msg = "msg example"; + const std::string exp_error_msg = + "Check 'value != 0' failed at test_file.cpp:341:\nFrontEnd API failed with GeneralFailure:\nmsg example\n"; + + OV_EXPECT_THROW(GeneralFailure::create(test_file, line, check_string, {}, msg), GeneralFailure, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(GeneralFailure::create({test_file, line, check_string}, {}, msg), GeneralFailure, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(FrontEndExceptionTest, create_initialization_failure) { + constexpr int line = 341; + constexpr char test_file[] = "test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string msg = "msg example"; + const std::string exp_error_msg = "Check 'value != 0' failed at test_file.cpp:341:\nFrontEnd API failed with " + "InitializationFailure:\nmsg example\n"; + + OV_EXPECT_THROW(InitializationFailure::create(test_file, line, check_string, {}, msg), InitializationFailure, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(InitializationFailure::create({test_file, line, check_string}, {}, msg), InitializationFailure, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(FrontEndExceptionTest, create_op_validation_failure) { + constexpr int line = 341; + constexpr char test_file[] = "test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string msg = "msg example"; + const std::string exp_error_msg = + "Check 'value != 0' failed at test_file.cpp:341:\nFrontEnd API failed with OpValidationFailure:\nmsg example\n"; + + OV_EXPECT_THROW(OpValidationFailure::create(test_file, line, check_string, {}, msg), OpValidationFailure, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(OpValidationFailure::create({test_file, line, check_string}, {}, msg), OpValidationFailure, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(FrontEndExceptionTest, create_op_conversion_failure) { + constexpr int line = 341; + constexpr char test_file[] = "test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string msg = "msg example"; + const std::string exp_error_msg = + "Check 'value != 0' failed at test_file.cpp:341:\nFrontEnd API failed with OpConversionFailure:\nmsg example\n"; + + OV_EXPECT_THROW(OpConversionFailure::create(test_file, line, check_string, {}, msg), OpConversionFailure, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(OpConversionFailure::create({test_file, line, check_string}, {}, msg), OpConversionFailure, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST(FrontEndExceptionTest, create_not_implemented_failure) { + constexpr int line = 341; + constexpr char test_file[] = "test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string msg = "msg example"; + const std::string exp_error_msg = "Check 'value != 0' failed at test_file.cpp:341:\nFrontEnd API failed with " + "NotImplementedFailure:\nmsg example\n"; + + OV_EXPECT_THROW(NotImplementedFailure::create(test_file, line, check_string, {}, msg), NotImplementedFailure, exp_error_msg); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(NotImplementedFailure::create({test_file, line, check_string}, {}, msg), NotImplementedFailure, exp_error_msg); + OPENVINO_SUPPRESS_DEPRECATED_END +} + // FrontEndManager exception safety #define CHECK_EXCEPTION_FRONTEND(statement) \ try { \ diff --git a/src/core/tests/node_test.cpp b/src/core/tests/node_test.cpp index 10d159aa1b9..0af685a307c 100644 --- a/src/core/tests/node_test.cpp +++ b/src/core/tests/node_test.cpp @@ -47,3 +47,52 @@ TEST_F(NodeValidationFailureTest, node_shape_infer_failure_message) { ov::NodeValidationFailure, HasSubstr("':\nShape inference input shapes {[1,2,3],[1]}\nTest message")); } + +TEST_F(NodeValidationFailureTest, create_node_validation_failure) { + constexpr int line = 145; + constexpr char test_file[] = "src/test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string explanation = "test error message"; + const std::string ctx_info = "My context"; + const std::string exp_error_msg1 = "Check 'value != 0' failed at src/test_file.cpp:145:\nWhile validating node"; + const std::string exp_error_msg2 = ":\ntest error message\n"; + + OV_EXPECT_THROW(ov::NodeValidationFailure::create(test_file, line, check_string, &test_node, explanation), + ov::NodeValidationFailure, + AllOf(HasSubstr(exp_error_msg1), HasSubstr(exp_error_msg2))); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW(ov::NodeValidationFailure::create({test_file, line, check_string}, &test_node, explanation), + ov::NodeValidationFailure, + AllOf(HasSubstr(exp_error_msg1), HasSubstr(exp_error_msg2))); + OPENVINO_SUPPRESS_DEPRECATED_END +} + +TEST_F(NodeValidationFailureTest, create_node_validation_failure_with_input_shapes) { + constexpr int line = 145; + constexpr char test_file[] = "src/test_file.cpp"; + constexpr char check_string[] = "value != 0"; + const std::string explanation = "test error message"; + const std::string ctx_info = "My context"; + const std::string exp_error_msg1 = "Check 'value != 0' failed at src/test_file.cpp:145:\nWhile validating node"; + const std::string exp_error_msg2 = "Shape inference input shapes {[1,2],[4]}\ntest error message\n"; + const auto input_shapes = std::vector{{1, 2}, {4}}; + + OV_EXPECT_THROW( + ov::NodeValidationFailure::create(test_file, + line, + check_string, + std::make_pair(static_cast(&test_node), &input_shapes), + explanation), + ov::NodeValidationFailure, + AllOf(HasSubstr(exp_error_msg1), HasSubstr(exp_error_msg2))); + + OPENVINO_SUPPRESS_DEPRECATED_START + OV_EXPECT_THROW( + ov::NodeValidationFailure::create({test_file, line, check_string}, + std::make_pair(static_cast(&test_node), &input_shapes), + explanation), + ov::NodeValidationFailure, + AllOf(HasSubstr(exp_error_msg1), HasSubstr(exp_error_msg2))); + OPENVINO_SUPPRESS_DEPRECATED_END +} diff --git a/src/frontends/common/include/openvino/frontend/exception.hpp b/src/frontends/common/include/openvino/frontend/exception.hpp index bed7e76898a..84e137ecdbd 100644 --- a/src/frontends/common/include/openvino/frontend/exception.hpp +++ b/src/frontends/common/include/openvino/frontend/exception.hpp @@ -20,6 +20,14 @@ public: const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + protected: explicit GeneralFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} }; @@ -31,6 +39,13 @@ public: const char* check_string, const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); protected: explicit InitializationFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} @@ -44,6 +59,14 @@ public: const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + protected: explicit OpValidationFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} }; @@ -56,6 +79,14 @@ public: const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + protected: explicit OpConversionFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} }; @@ -68,6 +99,14 @@ public: const std::string& context_info, const std::string& explanation); + [[noreturn]] OPENVINO_DEPRECATED( + "This function is deprecated and will be removed in the 2024.0 release") static void create(const CheckLocInfo& + check_loc_info, + const std::string& + context_info, + const std::string& + explanation); + protected: explicit NotImplementedFailure(const std::string& what_arg) : ov::AssertFailure(what_arg) {} }; diff --git a/src/frontends/common/src/exception.cpp b/src/frontends/common/src/exception.cpp index 1137da77c72..9af68477975 100644 --- a/src/frontends/common/src/exception.cpp +++ b/src/frontends/common/src/exception.cpp @@ -13,6 +13,12 @@ void ov::frontend::GeneralFailure::create(const char* file, make_what(file, line, check_string, "FrontEnd API failed with GeneralFailure" + context_info, explanation)); } +void ov::frontend::GeneralFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +} + void ov::frontend::InitializationFailure::create(const char* file, int line, const char* check_string, @@ -25,6 +31,12 @@ void ov::frontend::InitializationFailure::create(const char* file, explanation)); } +void ov::frontend::InitializationFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +} + void ov::frontend::OpValidationFailure::create(const char* file, int line, const char* check_string, @@ -37,6 +49,12 @@ void ov::frontend::OpValidationFailure::create(const char* file, explanation)); } +void ov::frontend::OpValidationFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +} + void ov::frontend::OpConversionFailure::create(const char* file, int line, const char* check_string, @@ -49,6 +67,12 @@ void ov::frontend::OpConversionFailure::create(const char* file, explanation)); } +void ov::frontend::OpConversionFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +} + void ov::frontend::NotImplementedFailure::create(const char* file, int line, const char* check_string, @@ -60,3 +84,9 @@ void ov::frontend::NotImplementedFailure::create(const char* file, "FrontEnd API failed with NotImplementedFailure" + context_info, explanation)); } + +void ov::frontend::NotImplementedFailure::create(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) { + create(check_loc_info.file, check_loc_info.line, check_loc_info.check_string, context_info, explanation); +}