Skip to content

Commit fe3bde5

Browse files
committed
update ORT Error Codes handling during Import & Compilation flow for OVEP
1 parent 70acefe commit fe3bde5

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

onnxruntime/core/providers/openvino/openvino_execution_provider.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66
#include <memory>
77
#include <vector>
8+
#include <charconv>
89
#include "core/providers/shared_library/provider_api.h"
910
#include "core/providers/openvino/openvino_execution_provider.h"
1011
#include "core/providers/openvino/contexts.h"
@@ -170,12 +171,19 @@ common::Status OpenVINOExecutionProvider::Compile(
170171
return 0;
171172
};
172173

173-
compute_info.compute_func = [](FunctionState state, const OrtApi* /* api */, OrtKernelContext* context) {
174+
compute_info.compute_func = [](FunctionState state, const OrtApi* /* api */, OrtKernelContext* context) -> Status {
174175
auto function_state = static_cast<OpenVINOEPFunctionState*>(state);
175176
try {
176177
function_state->backend_manager.Compute(context);
177178
} catch (const std::exception& ex) {
178-
return common::Status(common::ONNXRUNTIME, common::FAIL, ex.what());
179+
// Extract error code from message with pattern: "<code>|message"
180+
auto get_error_code = [](std::string_view msg) {
181+
if (auto pos = msg.find('|'); pos != std::string_view::npos)
182+
if (int code = 0; std::from_chars(msg.data(), msg.data() + pos, code).ec == std::errc{})
183+
return code;
184+
return static_cast<int>(common::EP_FAIL);
185+
};
186+
return common::Status(common::ONNXRUNTIME, get_error_code(ex.what()), ex.what());
179187
}
180188
return Status::OK();
181189
};

onnxruntime/core/providers/openvino/ov_interface.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,23 @@ namespace openvino_ep {
1818

1919
template <typename Func, typename... Args>
2020
inline auto OvExceptionBoundary(Func&& func, std::format_string<Args...>&& fmt, Args&&... args) {
21+
return OvExceptionBoundary(func, ORT_EP_FAIL, std::forward<std::format_string<Args...>>(fmt), std::forward<Args>(args)...);
22+
}
23+
24+
template <typename Func, typename... Args>
25+
inline auto OvExceptionBoundary(Func&& func, OrtErrorCode error_code, std::format_string<Args...>&& fmt, Args&&... args) {
2126
try {
2227
return func();
2328
} catch (const ov::Exception& e) {
24-
ORT_THROW(log_tag + std::vformat(fmt.get(), std::make_format_args(args...)) + ": " + std::string(e.what()));
29+
// Encode error code as prefix: "<code>|message"
30+
auto msg = std::format("{}|{}{}: {}", static_cast<int>(error_code), log_tag,
31+
std::vformat(fmt.get(), std::make_format_args(args...)), e.what());
32+
ORT_THROW(msg);
2533
} catch (...) {
26-
ORT_THROW(log_tag + std::vformat(fmt.get(), std::make_format_args(args...)));
34+
// Encode error code as prefix: "<code>|message"
35+
auto msg = std::format("{}|{}{}", static_cast<int>(error_code), log_tag,
36+
std::vformat(fmt.get(), std::make_format_args(args...)));
37+
ORT_THROW(msg);
2738
}
2839
}
2940

@@ -214,7 +225,8 @@ OVExeNetwork OVCore::ImportModel(ModelBlobWrapper& model_blob,
214225
#endif
215226
return exe;
216227
},
217-
"Exception while Loading Network for graph {}", name);
228+
ORT_INVALID_GRAPH,
229+
"Exception while importing model for graph {}", name);
218230
}
219231

220232
OVExeNetwork OVCore::ImportEPCtxOVIREncapsulation(std::istream& model_stream,

0 commit comments

Comments
 (0)