5 #include "config_origin.hpp"
6 #include <leatherman/locale/locale.hpp>
16 runtime_error(leatherman::locale::format(
"{1}: {2}", origin.
description(), message)) { }
19 config_exception(std::string
const& message, std::exception
const& e) : runtime_error(leatherman::locale::format(
"{1} {2}", message, e.what())) { }
29 std::string
const&
path, std::string
const& expected, std::string
const& actual) :
30 config_exception(origin, leatherman::locale::format(
"{1} has type {2} rather than {3}",
path, actual, expected)) { }
31 using config_exception::config_exception;
40 config_exception(leatherman::locale::format(
"No configuration setting found for key '{1}'",
path)) { }
41 using config_exception::config_exception;
50 missing_exception(origin, (expected.empty() ? leatherman::locale::format(
"Configuration key \"{1}\" is null",
path)
51 : leatherman::locale::format(
"Configuration key \"{1}\" is set to null but expected {2}",
path, expected))) { }
61 config_exception(origin, leatherman::locale::format(
"Invalid value at '{1}': {2}",
path, message)) { }
73 config_exception(origin,
path.empty() ? message : leatherman::locale::format(
"Invalid path '{1}': {2}",
path, message)) { }
112 parse_exception(origin, leatherman::locale::format(
"Could not resolve subtitution to a value: {1}", detail)) { }
138 path(std::move(path_)), origin(std::move(origin_)),
problem(std::move(problem_)) { }
140 const std::string
path;
141 const shared_origin origin;
144 std::string to_string() {
145 return leatherman::locale::format(
"ValidationProblem({1},{2},{3})",
path, origin->description(),
problem);
157 config_exception(make_message(problems_)), problems(std::move(problems_)) { }
159 const std::vector<validation_problem> problems;
162 static std::string make_message(std::vector<validation_problem>
const& problems_) {
164 for (
auto &p : problems_) {
165 auto sep = std::string(
": ");
166 for (
auto &s : {p.origin->description(), sep, p.path, sep, p.problem, std::string(
", ")}) {
171 throw bug_or_broken_exception(leatherman::locale::format(
"validation_failed_exception must have a non-empty list of problems"));
173 msg.resize(msg.length() - 2);