Catch exception on erroneous rules
std::regex and std::regex_replace may throw an std::regex_error if the expression or replacement contain errors. Log this error and carry on with the next rule, so that the title is shown even if the config contains errors.pull/1055/head
parent
b16c8972c7
commit
af3c868a5b
|
@ -141,10 +141,16 @@ std::string Window::rewriteTitle(const std::string& title)
|
||||||
|
|
||||||
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
||||||
if (it.key().isString() && it->isString()) {
|
if (it.key().isString() && it->isString()) {
|
||||||
|
try {
|
||||||
|
// malformated regexes will cause an exception.
|
||||||
|
// in this case, log error and try the next rule.
|
||||||
const std::regex rule{it.key().asString()};
|
const std::regex rule{it.key().asString()};
|
||||||
if (std::regex_match(title, rule)) {
|
if (std::regex_match(title, rule)) {
|
||||||
return std::regex_replace(title, rule, it->asString());
|
return std::regex_replace(title, rule, it->asString());
|
||||||
}
|
}
|
||||||
|
} catch (const std::regex_error& e) {
|
||||||
|
spdlog::error("Invalid rule {}: {}", it.key().asString(), e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue