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:
@@ -24,6 +24,7 @@
|
|||||||
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <filesystem>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -72,6 +73,18 @@ class Command final
|
|||||||
//! \brief Load given file path
|
//! \brief Load given file path
|
||||||
static void load(const std::string& 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};
|
std::string cmd{".L " + path};
|
||||||
Command::cmd_handler({cmd});
|
Command::cmd_handler({cmd});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user