From d1dc04020a3c9f5ceb1493c4b5ffd476bb260715 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 17 Jun 2023 20:39:08 +0800 Subject: [PATCH] Fastfetch: print error messages when failed to parse JSON config file --- src/fastfetch.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index fb548178b..d4e7a1afd 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -526,7 +526,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con static bool parseJsoncFile(FFinstance* instance, const char* path) { - yyjson_doc* doc = yyjson_read_file(path, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, NULL); + yyjson_read_err error; + yyjson_doc* doc = yyjson_read_file(path, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, &error); if (doc) { instance->state.configDoc = doc; @@ -544,6 +545,11 @@ static bool parseJsoncFile(FFinstance* instance, const char* path) } return true; } + else if (error.code != YYJSON_READ_ERROR_FILE_OPEN) + { + fprintf(stderr, "ERROR: failed to parse JSON config file `%s` at pos %zu: %s\n", path, error.pos, error.msg); + exit(477); + } return false; }