diff options
author | emersion <contact@emersion.fr> | 2018-06-30 12:28:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-30 12:28:17 +0100 |
commit | 09fdcfe7dfa4e53c08a5acfbfd49e1a3b4eea6e3 (patch) | |
tree | faf564fa5e998e4791f349cc905d33566ef6e8c3 /swaymsg | |
parent | Merge pull request #2171 from atomnuker/master (diff) | |
parent | refactor success_object (diff) | |
download | sway-09fdcfe7dfa4e53c08a5acfbfd49e1a3b4eea6e3.tar.gz sway-09fdcfe7dfa4e53c08a5acfbfd49e1a3b4eea6e3.tar.zst sway-09fdcfe7dfa4e53c08a5acfbfd49e1a3b4eea6e3.zip |
Merge pull request #2175 from apreiml/fix-swaymsg-error-output
fix swaymsg: errors are displayed again
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 29f2a907..4283bf00 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -19,30 +19,40 @@ void sway_terminate(int exit_code) { | |||
19 | exit(exit_code); | 19 | exit(exit_code); |
20 | } | 20 | } |
21 | 21 | ||
22 | static bool success_object(json_object *result) { | ||
23 | json_object *success; | ||
24 | |||
25 | if (!json_object_object_get_ex(result, "success", &success)) { | ||
26 | return false; | ||
27 | } | ||
28 | |||
29 | return json_object_get_boolean(success); | ||
30 | } | ||
31 | |||
22 | // Iterate results array and return false if any of them failed | 32 | // Iterate results array and return false if any of them failed |
23 | static bool success(json_object *r, bool fallback) { | 33 | static bool success(json_object *r, bool fallback) { |
24 | if (!json_object_is_type(r, json_type_array)) { | 34 | if (!json_object_is_type(r, json_type_array)) { |
25 | return fallback; | 35 | return fallback; |
26 | } | 36 | } |
37 | |||
27 | size_t results_len = json_object_array_length(r); | 38 | size_t results_len = json_object_array_length(r); |
28 | if (!results_len) { | 39 | if (!results_len) { |
29 | return fallback; | 40 | return fallback; |
30 | } | 41 | } |
42 | |||
31 | for (size_t i = 0; i < results_len; ++i) { | 43 | for (size_t i = 0; i < results_len; ++i) { |
32 | json_object *result = json_object_array_get_idx(r, i); | 44 | json_object *result = json_object_array_get_idx(r, i); |
33 | json_object *success; | 45 | |
34 | if (!json_object_object_get_ex(result, "success", &success)) { | 46 | if (!success_object(result)) { |
35 | return false; | ||
36 | } | ||
37 | if (!json_object_get_boolean(success)) { | ||
38 | return false; | 47 | return false; |
39 | } | 48 | } |
40 | } | 49 | } |
50 | |||
41 | return true; | 51 | return true; |
42 | } | 52 | } |
43 | 53 | ||
44 | static void pretty_print_cmd(json_object *r) { | 54 | static void pretty_print_cmd(json_object *r) { |
45 | if (!success(r, true)) { | 55 | if (!success_object(r)) { |
46 | json_object *error; | 56 | json_object *error; |
47 | if (!json_object_object_get_ex(r, "error", &error)) { | 57 | if (!json_object_object_get_ex(r, "error", &error)) { |
48 | printf("An unknkown error occurred"); | 58 | printf("An unknkown error occurred"); |
@@ -402,6 +412,7 @@ int main(int argc, char **argv) { | |||
402 | } else { | 412 | } else { |
403 | sway_abort("Unknown message type %s", cmdtype); | 413 | sway_abort("Unknown message type %s", cmdtype); |
404 | } | 414 | } |
415 | |||
405 | free(cmdtype); | 416 | free(cmdtype); |
406 | 417 | ||
407 | char *command = NULL; | 418 | char *command = NULL; |