*/
#pragma once
-void tree_append_json(const char *filename);
+void tree_append_json(const char *filename, char **errormsg);
void cmd_append_layout(I3_CMD, char *path) {
LOG("Appending layout \"%s\"\n", path);
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,
// false); should be enough, but when sending 'workspace 4; append_layout
restore_open_placeholder_windows(parent);
cmd_output->needs_tree_render = true;
- // XXX: default reply for now, make this a better reply
- ysuccess(true);
}
/*
return 1;
}
-void tree_append_json(const char *filename) {
+void tree_append_json(const char *filename, char **errormsg) {
FILE *f;
if ((f = fopen(filename, "r")) == NULL) {
LOG("Cannot open file \"%s\"\n", filename);
{
unsigned char *str = yajl_get_error(hand, 1, (const unsigned char*)buf, n);
ELOG("JSON parsing error: %s\n", str);
+ if (errormsg != NULL)
+ *errormsg = sstrdup((const char*)str);
yajl_free_error(hand, str);
/* In case not all containers were restored, we need to fix the
};
focused = croot;
- tree_append_json(globbed);
+ tree_append_json(globbed, NULL);
printf("appended tree, using new root\n");
croot = TAILQ_FIRST(&(croot->nodes_head));