aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/i3bar.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-09-21 12:06:25 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-09-21 15:10:47 +0100
commita2326661e190bd759dc0a99f34a3d69dcdf8dc57 (patch)
tree17d575cddd68579bdb5ae1aa1de168f1c9c4f51b /swaybar/i3bar.c
parentswaybar: reset tokener if json is incomplete (diff)
downloadsway-a2326661e190bd759dc0a99f34a3d69dcdf8dc57.tar.gz
sway-a2326661e190bd759dc0a99f34a3d69dcdf8dc57.tar.zst
sway-a2326661e190bd759dc0a99f34a3d69dcdf8dc57.zip
swaybar: log invalid i3bar json
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r--swaybar/i3bar.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 02b68a2a..325aa61a 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -117,7 +117,9 @@ bool i3bar_handle_readable(struct status_line *status) {
117 memmove(status->buffer, &status->buffer[c], status->buffer_index); 117 memmove(status->buffer, &status->buffer[c], status->buffer_index);
118 break; 118 break;
119 } else if (!isspace(status->buffer[c])) { 119 } else if (!isspace(status->buffer[c])) {
120 status_error(status, "[invalid json]"); 120 wlr_log(WLR_DEBUG, "Invalid i3bar json: expected '[' but encountered '%c'",
121 status->buffer[c]);
122 status_error(status, "[invalid i3bar json]");
121 return true; 123 return true;
122 } 124 }
123 } 125 }
@@ -155,6 +157,8 @@ bool i3bar_handle_readable(struct status_line *status) {
155 ++buffer_pos; 157 ++buffer_pos;
156 break; 158 break;
157 } else if (!isspace(status->buffer[buffer_pos])) { 159 } else if (!isspace(status->buffer[buffer_pos])) {
160 wlr_log(WLR_DEBUG, "Invalid i3bar json: expected ',' but encountered '%c'",
161 status->buffer[buffer_pos]);
158 status_error(status, "[invalid i3bar json]"); 162 status_error(status, "[invalid i3bar json]");
159 return true; 163 return true;
160 } 164 }
@@ -166,7 +170,8 @@ bool i3bar_handle_readable(struct status_line *status) {
166 } else { 170 } else {
167 test_object = json_tokener_parse_ex(status->tokener, 171 test_object = json_tokener_parse_ex(status->tokener,
168 &status->buffer[buffer_pos], status->buffer_index - buffer_pos); 172 &status->buffer[buffer_pos], status->buffer_index - buffer_pos);
169 if (json_tokener_get_error(status->tokener) == json_tokener_success) { 173 enum json_tokener_error err = json_tokener_get_error(status->tokener);
174 if (err == json_tokener_success) {
170 if (json_object_get_type(test_object) == json_type_array) { 175 if (json_object_get_type(test_object) == json_type_array) {
171 if (last_object) { 176 if (last_object) {
172 json_object_put(last_object); 177 json_object_put(last_object);
@@ -198,7 +203,7 @@ bool i3bar_handle_readable(struct status_line *status) {
198 continue; // look for comma without reading more input 203 continue; // look for comma without reading more input
199 } 204 }
200 buffer_pos = status->buffer_index = 0; 205 buffer_pos = status->buffer_index = 0;
201 } else if (json_tokener_get_error(status->tokener) == json_tokener_continue) { 206 } else if (err == json_tokener_continue) {
202 json_tokener_reset(status->tokener); 207 json_tokener_reset(status->tokener);
203 if (status->buffer_index < status->buffer_size) { 208 if (status->buffer_index < status->buffer_size) {
204 // move the object to the start of the buffer 209 // move the object to the start of the buffer
@@ -219,6 +224,10 @@ bool i3bar_handle_readable(struct status_line *status) {
219 } 224 }
220 } 225 }
221 } else { 226 } else {
227 char last_char = status->buffer[status->buffer_index - 1];
228 status->buffer[status->buffer_index - 1] = '\0';
229 wlr_log(WLR_DEBUG, "Failed to parse i3bar json - %s: '%s%c'",
230 json_tokener_error_desc(err), &status->buffer[buffer_pos], last_char);
222 status_error(status, "[failed to parse i3bar json]"); 231 status_error(status, "[failed to parse i3bar json]");
223 return true; 232 return true;
224 } 233 }