Skip to content

Commit

Permalink
issue #54 Add filesystem check for config file in ChatGPTIPAProvider
Browse files Browse the repository at this point in the history
Include <filesystem> header for file operations. Add a check in the
initialize method to verify the existence of ChatGPTIPAProvider.json.
Log an error and return early if the file is missing to prevent
runtime errors.
  • Loading branch information
schnelle committed Dec 19, 2024
1 parent f56174a commit 0409311
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include <fstream>
#include <filesystem>

#include <curl/curl.h>
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -65,6 +66,14 @@ void ChatGPTIPAProvider::initialize() {
std::string configFile = "config";
configFile += std::filesystem::path::preferred_separator;
configFile += "ChatGPTIPAProvider.json";
if (!std::filesystem::exists(configFile)) {
LOG4CPLUS_ERROR_FMT(
LOGGER,
LOG4CPLUS_TEXT(
"ChatGPT IPA provider configuration file %s not found"),
configFile.c_str());
return;
}
std::ifstream file(configFile);
nlohmann::json json = nlohmann::json::parse(file);
ChatGPTConfiguration configuration = json;
Expand Down

0 comments on commit 0409311

Please sign in to comment.