Skip to content

Commit

Permalink
show error for unknown key
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jul 9, 2017
1 parent 1b24a77 commit 8c2d555
Showing 1 changed file with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,51 @@ class frontmost_application final : public base {
type_(type::frontmost_application_if),
cached_update_count_(0),
cached_result_(true) {
{
const std::string key = "type";
if (json.find(key) != std::end(json) && json[key].is_string()) {
if (json[key] == "frontmost_application_if") {
type_ = type::frontmost_application_if;
}
if (json[key] == "frontmost_application_unless") {
type_ = type::frontmost_application_unless;
}
}
}
{
const std::string key = "bundle_identifiers";
if (json.find(key) != std::end(json) && json[key].is_array()) {
for (const auto& j : json[key]) {
if (j.is_string()) {
std::string s = j;
try {
std::regex r(s);
bundle_identifiers_.push_back(r);
} catch (std::exception& e) {
logger::get_logger().error("regex error: \"{0}\" {1}", s, e.what());
if (json.is_object()) {
for (auto it = std::begin(json); it != std::end(json); std::advance(it, 1)) {
// it.key() is always std::string.
const auto& key = it.key();
const auto& value = it.value();

if (key == "type") {
if (json.find(key) != std::end(json) && json[key].is_string()) {
if (json[key] == "frontmost_application_if") {
type_ = type::frontmost_application_if;
}
if (json[key] == "frontmost_application_unless") {
type_ = type::frontmost_application_unless;
}
}
}
}
}
{
const std::string key = "file_paths";
if (json.find(key) != std::end(json) && json[key].is_array()) {
for (const auto& j : json[key]) {
if (j.is_string()) {
std::string s = j;
try {
std::regex r(s);
file_paths_.push_back(r);
} catch (std::exception& e) {
logger::get_logger().error("regex error: \"{0}\" {1}", s, e.what());
} else if (key == "bundle_identifiers") {
if (json.find(key) != std::end(json) && json[key].is_array()) {
for (const auto& j : json[key]) {
if (j.is_string()) {
std::string s = j;
try {
std::regex r(s);
bundle_identifiers_.push_back(r);
} catch (std::exception& e) {
logger::get_logger().error("regex error: \"{0}\" {1}", s, e.what());
}
}
}
}
} else if (key == "file_paths") {
if (json.find(key) != std::end(json) && json[key].is_array()) {
for (const auto& j : json[key]) {
if (j.is_string()) {
std::string s = j;
try {
std::regex r(s);
file_paths_.push_back(r);
} catch (std::exception& e) {
logger::get_logger().error("regex error: \"{0}\" {1}", s, e.what());
}
}
}
}
} else {
logger::get_logger().error("unknown key: {0} in {1}", key, json.dump());
}
}
}
Expand Down

0 comments on commit 8c2d555

Please sign in to comment.