Skip to content

Commit 1d835cc

Browse files
authored
Include path in GetStringTaskType error (#448)
- mention the settings file path when GetStringTaskType fails to open the file - add a unit test validating that the thrown message contains the missing path
1 parent 190aec2 commit 1d835cc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

modules/core/performance/tests/perf_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ TEST_NOLINT(GetStringTaskTypeStandaloneTest, ThrowsIfFileMissing) {
164164
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, missing_path), std::runtime_error);
165165
}
166166

167+
TEST_NOLINT(GetStringTaskTypeStandaloneTest, ExceptionMessageContainsPath) {
168+
const std::string missing_path = "non_existent_settings.json";
169+
EXPECT_THROW_NOLINT(
170+
try { GetStringTaskType(ppc::core::TypeOfTask::kSEQ, missing_path); } catch (const std::runtime_error& e) {
171+
EXPECT_NE(std::string(e.what()).find(missing_path), std::string::npos);
172+
throw;
173+
},
174+
std::runtime_error);
175+
}
176+
167177
TEST(GetStringTaskTypeStandaloneTest, ReturnsUnknownForInvalidEnum) {
168178
std::string path = (std::filesystem::temp_directory_path() / "tmp_settings.json").string();
169179
std::ofstream(path) << R"({"tasks":{"seq":"SEQ"}})";

modules/core/task/include/task.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ inline std::string GetStringTaskStatus(StatusOfTask status_of_task) {
6262
inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string &settings_file_path) {
6363
std::ifstream file(settings_file_path);
6464
if (!file.is_open()) {
65-
throw std::runtime_error("Failed to open file settings.json");
65+
throw std::runtime_error("Failed to open " + settings_file_path);
6666
}
6767

6868
auto list_settings = ppc::util::InitJSONPtr();

0 commit comments

Comments
 (0)