diff options
| author | user <user@clank> | 2026-08-15 23:21:40 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-15 23:21:40 +0200 |
| commit | b9ae6cbcbce3816c2b2e8f760f082d3eaa3b5184 (patch) | |
| tree | 8dd1f16ac15edd16f51ba07e37c312ccb89f53f1 /src/cmd.c | |
| parent | sl0ppty: watch what the config was built from, not just what it was called (diff) | |
| download | slosh-b9ae6cbcbce3816c2b2e8f760f082d3eaa3b5184.tar.gz slosh-b9ae6cbcbce3816c2b2e8f760f082d3eaa3b5184.tar.xz slosh-b9ae6cbcbce3816c2b2e8f760f082d3eaa3b5184.zip | |
sl0ppty: say what the config could not honour
A config that half-applied said nothing. An unknown shader, a binding
that does not parse, an include that is not there: the file loaded, that
line did not, and the session announced "config reloaded" as though
nothing had happened. Every one of those messages was already being
produced -- config_load has filled `err` on a successful load since it
was written -- and then dropped on the floor by every caller, because a
non-zero return meant "fine".
So the complaint from the last load is kept, and the front end says it
where it would have said "config reloaded". Once at startup too: a config
that loaded with a complaint still started the session, and the stderr
line goes where nobody attached can read it. The `reload` control verb
answers `{"ok":true,"warning":"..."}` -- ok, because the file did apply,
with the reason attached for a script that cares.
Two things fell out of writing the test for it.
An include's complaint was reported by nobody when the file in the middle
was fine. apply_includes only looked at the return value, so a theme that
loaded while *its* include was missing swallowed the message: the child
returned true, and true meant there was nothing to say. The complaint now
travels up whether or not the include itself loaded.
And a complaint now carries the name of the file it happened in, exactly
once -- added by the file that produced it, never by the files that
included it, because prefixing at every level builds a chain that
truncates before the part that matters. So:
t.kdl: unknown shader: bloom
keys.kdl: line 2: unknown action fly
b.kdl: includes nested too deep (a cycle?)
cannot open /home/you/.config/sl0ppty/themes/nope.kdl
which is enough to know which file to open, in a message that fits in a
toast.
Diffstat (limited to 'src/cmd.c')
| -rw-r--r-- | src/cmd.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -278,7 +278,20 @@ static char *cmd_json(app_t *a, screen_t *s, input_parser_t *in, } app_resize(a, s->cols, s->rows); /* geometry may have moved */ s->force_full = true; - app_toast(a, "config reloaded"); + /* A complaint is not a failure: the file applied and one line of it did + * not, so the reply is ok with a reason attached rather than an error. A + * script that cares can look; the session says it out loud either way. */ + const char *why = app_config_complaint(); + app_toast(a, why && *why ? why : "config reloaded"); + if (why && *why) { + json_t j; + json_init(&j); + json_obj_open(&j, NULL); + json_bool(&j, "ok", true); + json_str(&j, "warning", why, strlen(why)); + json_obj_close(&j); + return j.buf; + } return jok_int(NULL, 0); } if (strcmp(cmd, "alive") == 0) { |
