From f4fc10af199421c13a9d073c42993b02925f76b5 Mon Sep 17 00:00:00 2001 From: ankitm3k Date: Fri, 31 Oct 2025 16:25:14 +0530 Subject: [PATCH] update ORT Error Codes handling during Import & Compilation flow for OVEP --- .../openvino/openvino_execution_provider.cc | 12 ++++++++++-- .../core/providers/openvino/ov_interface.cc | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 049af81c9ffb2..1504f023502aa 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "core/providers/shared_library/provider_api.h" #include "core/providers/openvino/openvino_execution_provider.h" #include "core/providers/openvino/contexts.h" @@ -170,12 +171,19 @@ common::Status OpenVINOExecutionProvider::Compile( return 0; }; - compute_info.compute_func = [](FunctionState state, const OrtApi* /* api */, OrtKernelContext* context) { + compute_info.compute_func = [](FunctionState state, const OrtApi* /* api */, OrtKernelContext* context) -> Status { auto function_state = static_cast(state); try { function_state->backend_manager.Compute(context); } catch (const std::exception& ex) { - return common::Status(common::ONNXRUNTIME, common::FAIL, ex.what()); + // Extract error code from message with pattern: "|message" + auto get_error_code = [](std::string_view msg) { + if (auto pos = msg.find('|'); pos != std::string_view::npos) + if (int code = 0; std::from_chars(msg.data(), msg.data() + pos, code).ec == std::errc{}) + return code; + return static_cast(common::EP_FAIL); + }; + return common::Status(common::ONNXRUNTIME, get_error_code(ex.what()), ex.what()); } return Status::OK(); }; diff --git a/onnxruntime/core/providers/openvino/ov_interface.cc b/onnxruntime/core/providers/openvino/ov_interface.cc index e97bbaceee4e2..8b17e3cd54c5d 100644 --- a/onnxruntime/core/providers/openvino/ov_interface.cc +++ b/onnxruntime/core/providers/openvino/ov_interface.cc @@ -18,12 +18,23 @@ namespace openvino_ep { template inline auto OvExceptionBoundary(Func&& func, std::format_string&& fmt, Args&&... args) { + return OvExceptionBoundary(func, ORT_EP_FAIL, std::forward>(fmt), std::forward(args)...); +} + +template +inline auto OvExceptionBoundary(Func&& func, OrtErrorCode error_code, std::format_string&& fmt, Args&&... args) { try { return func(); } catch (const ov::Exception& e) { - ORT_THROW(log_tag + std::vformat(fmt.get(), std::make_format_args(args...)) + ": " + std::string(e.what())); + // Encode error code as prefix: "|message" + auto msg = std::format("{}|{}{}: {}", static_cast(error_code), log_tag, + std::vformat(fmt.get(), std::make_format_args(args...)), e.what()); + ORT_THROW(msg); } catch (...) { - ORT_THROW(log_tag + std::vformat(fmt.get(), std::make_format_args(args...))); + // Encode error code as prefix: "|message" + auto msg = std::format("{}|{}{}", static_cast(error_code), log_tag, + std::vformat(fmt.get(), std::make_format_args(args...))); + ORT_THROW(msg); } } @@ -214,7 +225,8 @@ OVExeNetwork OVCore::ImportModel(ModelBlobWrapper& model_blob, #endif return exe; }, - "Exception while Loading Network for graph {}", name); + ORT_INVALID_GRAPH, + "Exception while importing model for graph {}", name); } OVExeNetwork OVCore::ImportEPCtxOVIREncapsulation(std::istream& model_stream,