diff options
author | Jason Nader <jason.nader@protonmail.com> | 2021-10-18 18:44:41 +0900 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-10-18 14:20:24 +0200 |
commit | 55cd8abd76cf6a31ca7edf67473c048f90f99140 (patch) | |
tree | f2e16f42d610c7c375bbd572c7d9c6eb95ce7fae /swaymsg | |
parent | f873bcc4e1b2d39edb9ca91ea60db24e6b6e42f2 (diff) |
swaymsg: be explicit about the json parser error
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index ce5d7d71..c3468a16 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -483,12 +483,12 @@ int main(int argc, char **argv) { // pretty print the json json_tokener *tok = json_tokener_new_ex(INT_MAX); json_object *obj = json_tokener_parse_ex(tok, resp, -1); + enum json_tokener_error err = json_tokener_get_error(tok); json_tokener_free(tok); - if (obj == NULL) { + if (obj == NULL || err != json_tokener_success) { if (!quiet) { - fprintf(stderr, "ERROR: Could not parse json response from ipc. " - "This is a bug in sway."); - printf("%s\n", resp); + sway_log(SWAY_ERROR, "failed to parse payload as json: %s", + json_tokener_error_desc(err)); } ret = 1; } else { @@ -522,11 +522,12 @@ int main(int argc, char **argv) { json_tokener *tok = json_tokener_new_ex(INT_MAX); 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); - if (obj == NULL) { + if (obj == NULL || err != json_tokener_success) { if (!quiet) { - fprintf(stderr, "ERROR: Could not parse json response from" - " ipc. This is a bug in sway."); + sway_log(SWAY_ERROR, "failed to parse payload as json: %s", + json_tokener_error_desc(err)); ret = 1; } break; |