From 42a0090ea472db34e87a35c11b302e3202207d77 Mon Sep 17 00:00:00 2001 From: "Aubry, Kyllian" Date: Fri, 17 May 2024 16:09:21 +0200 Subject: [PATCH] SKA-504: throw for nonexistent files (#27) --- advalues/adapter/AdManager.cpp | 6 ++++++ chardev/adapter/ChardevManager.cpp | 7 +++++++ gpio/adapter/GpioManager.cpp | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/advalues/adapter/AdManager.cpp b/advalues/adapter/AdManager.cpp index 8200ae2..c6aac13 100644 --- a/advalues/adapter/AdManager.cpp +++ b/advalues/adapter/AdManager.cpp @@ -3,6 +3,7 @@ #include "AdManager.hpp" #include +#include #include #include "../../util/Exceptions.hpp" @@ -46,6 +47,11 @@ void AdManager::InitAdaptersFromConfigFile(const YAML::Node& configFile, std::unique_ptr subDataSpec, pubDataSpec; std::string publisherName, subscriberName; + if (!std::filesystem::exists(fileValuesYaml.path + fileValuesYaml.fileName)) + { + throw std::runtime_error("file " + fileValuesYaml.path + fileValuesYaml.fileName + " does not exist"); + } + // Manage topic_subscribe if (!fileValuesYaml.topic_subscribe.empty()) { diff --git a/chardev/adapter/ChardevManager.cpp b/chardev/adapter/ChardevManager.cpp index c77a296..968b58d 100644 --- a/chardev/adapter/ChardevManager.cpp +++ b/chardev/adapter/ChardevManager.cpp @@ -2,6 +2,8 @@ #include "ChardevManager.hpp" +#include + #include "../../util/FileHelper.hpp" #include "../../util/Exceptions.hpp" @@ -71,6 +73,11 @@ void ChardevManager::InitAdaptersFromConfigFile(const YAML::Node& configFile, for (auto chardevYaml : chardevYAMLConfigs) { const std::string pathToFile = chardevYaml.path; + + if (!std::filesystem::exists(pathToFile)) + { + throw std::runtime_error("file " + pathToFile + " does not exist"); + } std::string pathToFile_ = pathToFile; for(std::size_t i = 0; i < pathToFile_.size(); ++i) diff --git a/gpio/adapter/GpioManager.cpp b/gpio/adapter/GpioManager.cpp index 09f0367..b2dd7b2 100644 --- a/gpio/adapter/GpioManager.cpp +++ b/gpio/adapter/GpioManager.cpp @@ -3,6 +3,7 @@ #include "GpioManager.hpp" #include +#include #include #include @@ -71,6 +72,11 @@ void GpioManager::InitAdaptersFromConfigFile(const YAML::Node& configFile, std::vector gpioYAMLConfigs; GetYamlConfig(chipNode, gpioYAMLConfigs, chipPath); + if (!std::filesystem::exists(chipPath)) + { + throw std::runtime_error("GPIO chip " + chipPath + " does not exist"); + } + const auto chipName = chipPath.substr(chipPath.find_last_of('/') + 1); auto ioc = std::make_unique();