diff --git a/common/include/villas/exceptions.hpp b/common/include/villas/exceptions.hpp index 39824a214..8226fddcf 100644 --- a/common/include/villas/exceptions.hpp +++ b/common/include/villas/exceptions.hpp @@ -1,4 +1,4 @@ -/** Custom exceptions. +/** Common exceptions. * * @file * @author Steffen Vogel @@ -32,6 +32,12 @@ #include #include +#include + +#ifdef LIBCONFIG_FOUND +#include +#endif /* LIBCONFIG_FOUND */ + namespace villas { class SystemError : public std::system_error { @@ -63,20 +69,16 @@ public: class JsonError : public std::runtime_error { protected: + const json_t *setting; json_error_t error; public: - JsonError(const json_error_t &err) : - std::runtime_error("Failed to decode JSON document"), - error(err) - { } - template - JsonError(const json_error_t &err, const std::string &what, Args&&... args) : - std::runtime_error(fmt::format(what, std::forward(args)...)) - { - (void) err; - } + JsonError(const json_t *s, const json_error_t &e, const std::string &what = std::string(), Args&&... args) : + std::runtime_error(fmt::format(what, std::forward(args)...)), + setting(s), + error(e) + { } virtual const char * what() const noexcept { @@ -90,18 +92,27 @@ public: class ConfigError : public std::runtime_error { protected: - + /** A setting-id referencing the setting. */ std::string id; json_t *setting; + json_error_t error; public: template - ConfigError(json_t *s, const std::string &i, const std::string &what, Args&&... args) : + ConfigError(json_t *s, const std::string &i, const std::string &what = "Failed to parse configuration", Args&&... args) : std::runtime_error(fmt::format(what, std::forward(args)...)), id(i), setting(s) { } + template + ConfigError(json_t *s, const json_error_t &e, const std::string &i, const std::string &what = "Failed to parse configuration", Args&&... args) : + std::runtime_error(fmt::format(what, std::forward(args)...)), + id(i), + setting(s), + error(e) + { } + std::string docUri() const { std::string baseUri = "https://villas.fein-aachen.org/doc/jump?"; @@ -113,9 +124,8 @@ public: { std::stringstream ss; - ss << "Invalid configuration setting: " << std::endl; - ss << " Please consult the user documentation for details:" << std::endl; - ss << " " << docUri() << std::endl; + ss << std::runtime_error::what() << std::endl; + ss << " Please consult the user documentation for details: " << docUri(); auto str = new std::string(ss.str());