From 75a86a9df557352ed2e1c930b02c9f4e418097e7 Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 23 Jan 2018 20:40:14 +0100 Subject: [PATCH] error checking --- CMakeLists.txt | 2 +- README.md | 1 + src/soupbot.cpp | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5e9e60..70ec374 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7) include(GNUInstallDirs) project (soupbot - VERSION 0.2.2 + VERSION 0.2.3 LANGUAGES CXX ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall") diff --git a/README.md b/README.md index 323a732..9bf457d 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ You will need a pre-generated authentication code. | 16 | Connection failed | | 17 | TLS error | | 18 | Invalid response from server | +| 32 | File not readable | | 100 - 999 | HTTP status codes | | 65535 | Unknown exception | diff --git a/src/soupbot.cpp b/src/soupbot.cpp index 7cd177e..3348035 100644 --- a/src/soupbot.cpp +++ b/src/soupbot.cpp @@ -100,17 +100,26 @@ int main(int argc, char *argv[]) pt::ptree config; string instance = ""; string access_token = ""; - - read_config(config, instance, access_token); - pt::ptree ingredients; - pt::read_json(filepath + "ingredients.json", ingredients); std::vector vegetables; std::vector spices; std::vector fruits; std::vector misc; std::vector highprio; + read_config(config, instance, access_token); + + try + { + pt::read_json(filepath + "ingredients.json", ingredients); + } + catch (std::exception &e) + { + // most likely file not found + std::cerr << "ERROR: " << filepath << "ingredients.json not found or not readable.\n"; + return 32; + } + populate_vector(ingredients, "vegetables", vegetables); populate_vector(ingredients, "spices", spices); populate_vector(ingredients, "fruits", fruits);