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)); return dereference<T>(move(section), move(key), move(string_value), move(result));
} catch (const key_error& err) { } catch (const key_error& err) {
return default_value; 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) { } catch (const key_error& err) {
break; 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) { } catch (const std::exception& e) {
logger::make().err(e.what()); logger::make().err("Signal receiver raised an exception: %s", e.what());
} }
return false; return false;

View File

@ -201,7 +201,13 @@ chrono::duration<double> config::convert(string&& value) const {
template <> template <>
rgba config::convert(string&& value) const { 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 <> template <>

View File

@ -224,6 +224,10 @@ rgba parser::parse_color(const string& s, rgba fallback) {
rgba ret = rgba{s}; rgba ret = rgba{s};
if (!ret.has_color() || ret.m_type == rgba::ALPHA_ONLY) { 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; return fallback;
} }

View File

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