diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-10-22 21:15:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-22 21:15:43 -0400 |
commit | b31b11f13969eba777a9cb3b100baef1f919efad (patch) | |
tree | 06c66f34523546b3a21dae6a6edcadc6f7decc6d /swaygrab/json.c | |
parent | d10e72318315fa8ad0772f685f24cf2c9e2b5cc2 (diff) | |
parent | 29f27c7cdc9e11aa560a5d49d110fc705dbc21cb (diff) |
Merge pull request #1425 from ggreer/grab-error
swaygrab: Add some error handling.
Diffstat (limited to 'swaygrab/json.c')
-rw-r--r-- | swaygrab/json.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/swaygrab/json.c b/swaygrab/json.c index 32b68612..286085c3 100644 --- a/swaygrab/json.c +++ b/swaygrab/json.c @@ -21,6 +21,14 @@ void init_json_tree(int socketfd) { if (!tree || tok->err != json_tokener_success) { sway_abort("Unable to parse IPC response as JSON: %s", json_tokener_error_desc(tok->err)); } + json_object *success; + json_object_object_get_ex(tree, "success", &success); + if (success && !json_object_get_boolean(success)) { + json_object *error; + json_object_object_get_ex(tree, "error", &error); + sway_abort("IPC request failed: %s", json_object_get_string(error)); + } + json_object_put(success); json_tokener_free(tok); } @@ -72,7 +80,9 @@ json_object *get_focused_container() { char *get_focused_output() { json_object *outputs, *output, *name; json_object_object_get_ex(tree, "nodes", &outputs); - + if (!outputs) { + sway_abort("Unabled to get focused output. No nodes in tree."); + } for (int i = 0; i < json_object_array_length(outputs); i++) { output = json_object_array_get_idx(outputs, i); |