Print error message for invalid color strings

This commit is contained in:
patrick96 2019-10-27 23:19:36 +01:00 committed by Patrick Ziegler
parent c9efd09f71
commit eeab4f0d45
5 changed files with 18 additions and 3 deletions

View File

@ -105,6 +105,9 @@ class config {
return dereference<T>(move(section), move(key), move(string_value), move(result));
} catch (const key_error& err) {
return default_value;
} catch (const value_error& err) {
m_log.err("Invalid value for \"%s.%s\", using default value (reason: %s)", section, key, err.what());
return default_value;
}
}
@ -165,6 +168,9 @@ class config {
}
} catch (const key_error& err) {
break;
} catch (const value_error& err) {
m_log.err("Invalid value in list \"%s.%s\", using list as-is (reason: %s)", section, key, err.what());
return default_value;
}
}

View File

@ -34,7 +34,7 @@ class signal_emitter {
}
}
} catch (const std::exception& e) {
logger::make().err(e.what());
logger::make().err("Signal receiver raised an exception: %s", e.what());
}
return false;

View File

@ -201,7 +201,13 @@ chrono::duration<double> config::convert(string&& value) const {
template <>
rgba config::convert(string&& value) const {
return rgba{value};
rgba ret{value};
if (!ret.has_color()) {
throw value_error("\"" + value + "\" is an invalid color value.");
}
return ret;
}
template <>

View File

@ -224,6 +224,10 @@ rgba parser::parse_color(const string& s, rgba fallback) {
rgba ret = rgba{s};
if (!ret.has_color() || ret.m_type == rgba::ALPHA_ONLY) {
logger::make().warn(
"Invalid color in formatting tag detected: \"%s\", using fallback \"%s\". This is an issue with one of your "
"formatting tags. If it is not, please report this as a bug.",
s, static_cast<string>(fallback));
return fallback;
}

View File

@ -58,7 +58,6 @@ rgba::rgba(string hex) {
hex = normalize_hex(hex);
if (hex.length() == 0) {
// TODO we need a way to inform the user that their color was malformed
m_value = 0;
m_type = NONE;
} else if (hex.length() == 2) {