From 3a7fbc790d656b40e9e492d9d764aa463dbc8b3f Mon Sep 17 00:00:00 2001 From: Joscha Schmiedt <joscha@schmiedt.dev> Date: Mon, 28 Oct 2024 21:07:44 +0100 Subject: [PATCH] Add exception to load_string_file when path does not exist --- src/linkahead/utility.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/linkahead/utility.cpp b/src/linkahead/utility.cpp index fe229d1..21521ec 100644 --- a/src/linkahead/utility.cpp +++ b/src/linkahead/utility.cpp @@ -108,6 +108,10 @@ template <> auto getEnumValueFromName<Role>(const std::string &name) -> Role { auto load_string_file(const path &file_path) -> std::string { std::string result; + if (!exists(file_path)) { + throw std::runtime_error("File not found: " + file_path.string()); + } + // adapted from boost::filesystem::load_string_file, which was removed in 1.84 std::ifstream file; file.exceptions(std::ios_base::failbit | std::ios_base::badbit); -- GitLab