return parse errors via IPC for append_layout

This commit is contained in:
Michael Stapelberg 2014-01-04 21:39:13 +01:00
parent 1d969e6340
commit 58b3c730e2
4 changed files with 17 additions and 6 deletions

View File

@ -10,4 +10,4 @@
*/ */
#pragma once #pragma once
void tree_append_json(const char *filename); void tree_append_json(const char *filename, char **errormsg);

View File

@ -869,7 +869,18 @@ void cmd_nop(I3_CMD, char *comment) {
void cmd_append_layout(I3_CMD, char *path) { void cmd_append_layout(I3_CMD, char *path) {
LOG("Appending layout \"%s\"\n", path); LOG("Appending layout \"%s\"\n", path);
Con *parent = focused; Con *parent = focused;
tree_append_json(path); char *errormsg = NULL;
tree_append_json(path, &errormsg);
if (errormsg != NULL) {
yerror(errormsg);
free(errormsg);
/* Note that we continue executing since tree_append_json() has
* side-effects user-provided layouts can be partly valid, partly
* invalid, leading to half of the placeholder containers being
* created. */
} else {
ysuccess(true);
}
// XXX: This is a bit of a kludge. Theoretically, render_con(parent, // XXX: This is a bit of a kludge. Theoretically, render_con(parent,
// false); should be enough, but when sending 'workspace 4; append_layout // false); should be enough, but when sending 'workspace 4; append_layout
@ -882,8 +893,6 @@ void cmd_append_layout(I3_CMD, char *path) {
restore_open_placeholder_windows(parent); restore_open_placeholder_windows(parent);
cmd_output->needs_tree_render = true; cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
} }
/* /*

View File

@ -384,7 +384,7 @@ static int json_double(void *ctx, double val) {
return 1; return 1;
} }
void tree_append_json(const char *filename) { void tree_append_json(const char *filename, char **errormsg) {
FILE *f; FILE *f;
if ((f = fopen(filename, "r")) == NULL) { if ((f = fopen(filename, "r")) == NULL) {
LOG("Cannot open file \"%s\"\n", filename); LOG("Cannot open file \"%s\"\n", filename);
@ -441,6 +441,8 @@ void tree_append_json(const char *filename) {
{ {
unsigned char *str = yajl_get_error(hand, 1, (const unsigned char*)buf, n); unsigned char *str = yajl_get_error(hand, 1, (const unsigned char*)buf, n);
ELOG("JSON parsing error: %s\n", str); ELOG("JSON parsing error: %s\n", str);
if (errormsg != NULL)
*errormsg = sstrdup((const char*)str);
yajl_free_error(hand, str); yajl_free_error(hand, str);
/* In case not all containers were restored, we need to fix the /* In case not all containers were restored, we need to fix the

View File

@ -84,7 +84,7 @@ bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) {
}; };
focused = croot; focused = croot;
tree_append_json(globbed); tree_append_json(globbed, NULL);
printf("appended tree, using new root\n"); printf("appended tree, using new root\n");
croot = TAILQ_FIRST(&(croot->nodes_head)); croot = TAILQ_FIRST(&(croot->nodes_head));