Fastfetch: print error messages when failed to parse JSON config file

This commit is contained in:
Carter Li
2023-06-17 20:39:08 +08:00
parent 64bdb59683
commit d1dc04020a
+7 -1
View File
@@ -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;
}