container: root: macro: common: throw if invalid loading path

- Fixes silent failure when attempting to load non-existent/invalid path
- Applies to any macro, plugin or path that's loaded through this class
This commit is contained in:
2025-11-13 16:56:36 -08:00
parent 1c352f278b
commit 8c76e7cc11

View File

@@ -24,6 +24,7 @@
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
#include <ctime>
#include <filesystem>
#include <initializer_list>
#include <iostream>
#include <string>
@@ -72,6 +73,18 @@ class Command final
//! \brief Load given file path
static void load(const std::string& path)
{
std::filesystem::path p(path);
if (!std::filesystem::exists(p))
{
throw std::runtime_error(
std::string{"'" + path + "' does not exist!"}.c_str());
}
if (!std::filesystem::is_regular_file(p))
{
throw std::runtime_error(
std::string{"'" + path + "' is not a regular file!"}.c_str());
}
std::string cmd{".L " + path};
Command::cmd_handler({cmd});
}