Skip to content

Commit 0c30bc3

Browse files
authored
Add xrt::runner::json_error for consistency (#8945)
Json parsing errors, while throwing json::exception, the runner will catch and re-throw as xrt::runner::json_error. Signed-off-by: Soren Soe <[email protected]>
1 parent 78c9a82 commit 0c30bc3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/runtime_src/core/common/runner/runner.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const json empty_json;
6363
static json
6464
load_json(const std::string& input)
6565
{
66+
using json_error = xrt_core::runner::json_error;
6667
try {
6768
// Try parse as in-memory json
6869
return json::parse(input);
@@ -72,10 +73,15 @@ load_json(const std::string& input)
7273
// Not a valid JSON - treat input as a file path
7374
}
7475

75-
if (std::ifstream f{input})
76-
return json::parse(f);
76+
try {
77+
if (std::ifstream f{input})
78+
return json::parse(f);
79+
}
80+
catch (const std::exception& ex) {
81+
throw json_error(ex.what());
82+
}
7783

78-
throw std::runtime_error("Failed to open JSON file: " + input);
84+
throw std::runtime_error("Failed to load json, unknown error");
7985
}
8086

8187
// Lifted from xrt_kernel.cpp

src/runtime_src/core/common/runner/runner.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class runner : public xrt::detail::pimpl<runner_impl>
4242
what() const noexcept override;
4343
};
4444

45+
class json_error : public error
46+
{
47+
using error::error;
48+
};
49+
4550
class recipe_error : public error
4651
{
4752
using error::error;

0 commit comments

Comments
 (0)