mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
Fastfetch: improves error message for config errors
This commit is contained in:
+13
-7
@@ -404,20 +404,26 @@ static bool parseJsoncFile(FFdata* data, const char* path, yyjson_read_flag flg)
|
||||
}
|
||||
|
||||
{
|
||||
const char* error = NULL;
|
||||
|
||||
yyjson_val* const root = yyjson_doc_get_root(data->configDoc);
|
||||
if (!yyjson_is_obj(root)) {
|
||||
error = "Invalid JSON config format. Root value must be an object";
|
||||
fputs("JsonConfig Error: Invalid JSON config format. Root value must be an object", stderr);
|
||||
exit(477);
|
||||
}
|
||||
|
||||
yyjson_val* problematicKey = NULL;
|
||||
const char* error = NULL;
|
||||
const char* problematicModule = NULL;
|
||||
if (
|
||||
error ||
|
||||
(error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) ||
|
||||
(error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) ||
|
||||
(error = ffOptionsParseDisplayJsonConfig(&instance.config.display, root)) ||
|
||||
((error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root, &problematicKey)) && (problematicModule = "logo")) ||
|
||||
((error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root, &problematicKey)) && (problematicModule = "general")) ||
|
||||
((error = ffOptionsParseDisplayJsonConfig(&instance.config.display, root, &problematicKey)) && (problematicModule = "display")) ||
|
||||
false) {
|
||||
fprintf(stderr, "JsonConfig Error: %s\n", error);
|
||||
if (problematicKey) {
|
||||
fprintf(stderr, "JsonConfig Error (%s.%s): %s\n", problematicModule, unsafe_yyjson_get_str(problematicKey), error);
|
||||
} else {
|
||||
fprintf(stderr, "JsonConfig Error (%s): %s\n", problematicModule, error);
|
||||
}
|
||||
exit(477);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root) {
|
||||
const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root, yyjson_val** pkey) {
|
||||
yyjson_val* object = yyjson_obj_get(root, "display");
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -19,6 +19,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach (object, idx, max, key, val) {
|
||||
*pkey = key;
|
||||
if (unsafe_yyjson_equals_str(key, "stat")) {
|
||||
if (yyjson_is_bool(val)) {
|
||||
if (yyjson_get_bool(val)) {
|
||||
|
||||
@@ -90,7 +90,7 @@ typedef struct FFOptionsDisplay {
|
||||
FFlist constants; // list of FFstrbuf
|
||||
} FFOptionsDisplay;
|
||||
|
||||
const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root);
|
||||
const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root, yyjson_val** pkey);
|
||||
bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key, const char* value);
|
||||
void ffOptionsInitDisplay(FFOptionsDisplay* options);
|
||||
void ffOptionsDestroyDisplay(FFOptionsDisplay* options);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root) {
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root, yyjson_val** pkey) {
|
||||
yyjson_val* object = yyjson_obj_get(root, "general");
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -18,6 +18,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach (object, idx, max, key, val) {
|
||||
*pkey = key;
|
||||
if (unsafe_yyjson_equals_str(key, "thread")) {
|
||||
options->multithreading = yyjson_get_bool(val);
|
||||
} else if (unsafe_yyjson_equals_str(key, "processingTimeout")) {
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef struct FFOptionsGeneral {
|
||||
#endif
|
||||
} FFOptionsGeneral;
|
||||
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root);
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root, yyjson_val** pkey);
|
||||
bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value);
|
||||
void ffOptionsInitGeneral(FFOptionsGeneral* options);
|
||||
void ffOptionsDestroyGeneral(FFOptionsGeneral* options);
|
||||
|
||||
+2
-1
@@ -216,7 +216,7 @@ void ffOptionsDestroyLogo(FFOptionsLogo* options) {
|
||||
}
|
||||
}
|
||||
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root) {
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root, yyjson_val** pkey) {
|
||||
yyjson_val* object = yyjson_obj_get(root, "logo");
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -242,6 +242,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach (object, idx, max, key, val) {
|
||||
*pkey = key;
|
||||
if (unsafe_yyjson_equals_str(key, "type")) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
|
||||
+1
-1
@@ -57,5 +57,5 @@ typedef struct FFOptionsLogo {
|
||||
void ffOptionsInitLogo(FFOptionsLogo* options);
|
||||
bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value);
|
||||
void ffOptionsDestroyLogo(FFOptionsLogo* options);
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root);
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root, yyjson_val** pkey);
|
||||
void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options);
|
||||
|
||||
Reference in New Issue
Block a user