From 87757b4f0fe9dad041546d0c86a83d918c0aae92 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sat, 30 Jul 2022 08:15:29 +0100 Subject: Improve error message for invalid colours. --- src/color.c | 2 +- src/config.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/color.c b/src/color.c index 0ccd5b8..3fd9516 100644 --- a/src/color.c +++ b/src/color.c @@ -36,7 +36,7 @@ struct color hex_to_color(const char *hex) } else if (len == 8) { val = strtol(hex, NULL, 16); } else { - log_error("Invalid hex color %s\n", hex); + return (struct color) { -1, -1, -1, -1 }; } return (struct color) { diff --git a/src/config.c b/src/config.c index 9b0fe91..a0e77b2 100644 --- a/src/config.c +++ b/src/config.c @@ -399,7 +399,14 @@ uint32_t parse_anchor(const char *filename, size_t lineno, const char *str, bool struct color parse_color(const char *filename, size_t lineno, const char *str, bool *err) { - return hex_to_color(str); + struct color color = hex_to_color(str); + if (color.r == -1) { + PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as a color.\n", str); + if (err) { + *err = true; + } + } + return color; } uint32_t parse_uint32(const char *filename, size_t lineno, const char *str, bool *err) -- cgit v1.2.3