pbakaus/impeccable · error

{}

Error message

{}

What it means

A generic wrapper: the message text is fully supplied by the error returned from read_json_file when the --update payload cannot be read or parsed. run() prints it and exits 1, so the actual cause (path resolution failure, unreadable file, invalid JSON) is in the payload error string, not in the code itself.

Solutions

  1. Read the printed message for the underlying cause (path or JSON error) and fix accordingly.
  2. Verify the payload exists relative to the cwd serve-question runs in; use an absolute path if unsure.
  3. Validate the payload JSON parses (e.g. with a JSON linter) before re-running --update.

Example fix

// before
serve-question --update --key q-123 --payload ./round2.josn
// after
serve-question --update --key q-123 --payload /abs/path/round2.json
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const payloadPath = jspResolve(cwd, pp);
JSON.parse(fs.readFileSync(payloadPath, 'utf8')); // throws early with a clear message

Type guard

const isReadableJson = (p) => { try { JSON.parse(require('fs').readFileSync(p, 'utf8')); return true; } catch { return false; } };

Try / catch

const res = spawnSync('serve-question', args);
if (res.status === 1) {
  const msg = res.stderr.trim();
  if (msg.includes('No such file')) fixPath(); else if (msg.includes('parse')) fixJson();
}

Prevention

When it happens

Trigger: Calling `serve-question --update --key <k> --payload <f>` where read_json_file of the resolved payload path returns Err — nonexistent file, permission problem, or malformed JSON.

Common situations: Payload written to a different working directory than the one serve-question resolves from; JSON truncated by a failed write; typo in the payload filename.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of pbakaus/impeccable@2bc2879276 (2026-09-08). Data as JSON: /api/errors/b3808c8d5c71c7ee. Report an issue: GitHub.

Appendix: source

Thrown at crates/context/src/serve_question.rs:297

                kill_pid(pid as i64);
            }
        }
        let _ = std::fs::remove_file(answer_file(&qdir, &key));
        let _ = std::fs::remove_file(state_file(&qdir, &key));
        io.out("stopped\n");
        return 0;
    }

    if a.has("update") {
        let key = a.arg("key");
        let (Some(key), Some(pp)) = (key, payload_path.clone()) else {
            io.err("serve-question: --update needs --key and --payload\n");
            return 1;
        };
        let next_round = match read_json_file(&jsp::resolve(&cwd, &[&pp])) {
            Ok(v) => v,
            Err(msg) => {
                io.err(&format!("{}\n", msg));
                return 1;
            }
        };
        let ok = next_round.get("options").and_then(|o| o.as_array()).map(|o| !o.is_empty()).unwrap_or(false);
        if !ok {
            io.err("serve-question: --update payload needs an options array; nothing was delivered. Fix the payload and rerun --update on the same key.\n");
            return 1;
        }
        if !is_alive(&qdir, &key) {
            io.err("serve-question: no live question server for that key; the page it served is gone too. Re-present the round with --start and a fresh key, or fall back to the structured question tool.\n");
            return 2;
        }
        let delivered = next_file(&qdir, &key);
        let _ = std::fs::copy(jsp::resolve(&cwd, &[&pp]), &delivered);
        touch_now(&delivered);
        io.out("next round delivered; the page reloads itself\n");
        return 0;
    }

View on GitHub (pinned to 2bc2879276)