diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2021-10-21 22:47:35 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-10-22 09:57:05 +0200 |
commit | b223f702500d7cda6336e948062d680f07f34f66 (patch) | |
tree | 96b59cf413046634b6d6a647a35994123356d54a /swaymsg | |
parent | 96baef8ae9955dd7ffd85c6b769a14df1f95bc97 (diff) |
refactor: use sway_abort instead
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index dcf42cb6..e469319a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -487,32 +487,33 @@ int main(int argc, char **argv) { // pretty print the json json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); if (tok == NULL) { - sway_log(SWAY_ERROR, "failed allocating json_tokener"); + if (quiet) { + exit(EXIT_FAILURE); + } + sway_abort("failed allocating json_tokener"); + } + 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 || err != json_tokener_success) { + if (!quiet) { + sway_log(SWAY_ERROR, "failed to parse payload as json: %s", + json_tokener_error_desc(err)); + } ret = 1; } else { - 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 || err != json_tokener_success) { - if (!quiet) { - sway_log(SWAY_ERROR, "failed to parse payload as json: %s", - json_tokener_error_desc(err)); - } - ret = 1; - } else { - if (!success(obj, true)) { - ret = 2; - } - if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { - if (raw) { - printf("%s\n", json_object_to_json_string_ext(obj, - JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); - } else { - pretty_print(type, obj); - } + if (!success(obj, true)) { + ret = 2; + } + if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { + if (raw) { + printf("%s\n", json_object_to_json_string_ext(obj, + JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); + } else { + pretty_print(type, obj); } - json_object_put(obj); } + json_object_put(obj); } free(command); free(resp); @@ -531,9 +532,10 @@ int main(int argc, char **argv) { json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); if (tok == NULL) { - sway_log(SWAY_ERROR, "failed allocating json_tokener"); - ret = 1; - break; + if (quiet) { + exit(EXIT_FAILURE); + } + sway_abort("failed allocating json_tokener"); } json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); enum json_tokener_error err = json_tokener_get_error(tok); |