mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
swaygrab: Add some error handling.
- If IPC response contains `success: false`, abort and print error message. - If tree has no nodes, abort with error msg instead of segfaulting.
This commit is contained in:
parent
d10e723183
commit
29f27c7cdc
|
@ -21,6 +21,14 @@ void init_json_tree(int socketfd) {
|
||||||
if (!tree || tok->err != json_tokener_success) {
|
if (!tree || tok->err != json_tokener_success) {
|
||||||
sway_abort("Unable to parse IPC response as JSON: %s", json_tokener_error_desc(tok->err));
|
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);
|
json_tokener_free(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +80,9 @@ json_object *get_focused_container() {
|
||||||
char *get_focused_output() {
|
char *get_focused_output() {
|
||||||
json_object *outputs, *output, *name;
|
json_object *outputs, *output, *name;
|
||||||
json_object_object_get_ex(tree, "nodes", &outputs);
|
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++) {
|
for (int i = 0; i < json_object_array_length(outputs); i++) {
|
||||||
output = json_object_array_get_idx(outputs, i);
|
output = json_object_array_get_idx(outputs, i);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue