swaymsg: be explicit about the json parser error

This commit is contained in:
Jason Nader 2021-10-18 18:44:41 +09:00 committed by Simon Ser
parent f873bcc4e1
commit 55cd8abd76

View file

@ -483,12 +483,12 @@ int main(int argc, char **argv) {
// pretty print the json // pretty print the json
json_tokener *tok = json_tokener_new_ex(INT_MAX); json_tokener *tok = json_tokener_new_ex(INT_MAX);
json_object *obj = json_tokener_parse_ex(tok, resp, -1); json_object *obj = json_tokener_parse_ex(tok, resp, -1);
enum json_tokener_error err = json_tokener_get_error(tok);
json_tokener_free(tok); json_tokener_free(tok);
if (obj == NULL) { if (obj == NULL || err != json_tokener_success) {
if (!quiet) { if (!quiet) {
fprintf(stderr, "ERROR: Could not parse json response from ipc. " sway_log(SWAY_ERROR, "failed to parse payload as json: %s",
"This is a bug in sway."); json_tokener_error_desc(err));
printf("%s\n", resp);
} }
ret = 1; ret = 1;
} else { } else {
@ -522,11 +522,12 @@ int main(int argc, char **argv) {
json_tokener *tok = json_tokener_new_ex(INT_MAX); json_tokener *tok = json_tokener_new_ex(INT_MAX);
json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1);
enum json_tokener_error err = json_tokener_get_error(tok);
json_tokener_free(tok); json_tokener_free(tok);
if (obj == NULL) { if (obj == NULL || err != json_tokener_success) {
if (!quiet) { if (!quiet) {
fprintf(stderr, "ERROR: Could not parse json response from" sway_log(SWAY_ERROR, "failed to parse payload as json: %s",
" ipc. This is a bug in sway."); json_tokener_error_desc(err));
ret = 1; ret = 1;
} }
break; break;