{"record":{"id":"b3808c8d5c71c7ee","repo":"pbakaus/impeccable","slug":"error-b3808c","errorCode":null,"errorMessage":"{}\n","messagePattern":"\\{\\}\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/serve_question.rs","lineNumber":297,"sourceCode":"                kill_pid(pid as i64);\n            }\n        }\n        let _ = std::fs::remove_file(answer_file(&qdir, &key));\n        let _ = std::fs::remove_file(state_file(&qdir, &key));\n        io.out(\"stopped\\n\");\n        return 0;\n    }\n\n    if a.has(\"update\") {\n        let key = a.arg(\"key\");\n        let (Some(key), Some(pp)) = (key, payload_path.clone()) else {\n            io.err(\"serve-question: --update needs --key and --payload\\n\");\n            return 1;\n        };\n        let next_round = match read_json_file(&jsp::resolve(&cwd, &[&pp])) {\n            Ok(v) => v,\n            Err(msg) => {\n                io.err(&format!(\"{}\\n\", msg));\n                return 1;\n            }\n        };\n        let ok = next_round.get(\"options\").and_then(|o| o.as_array()).map(|o| !o.is_empty()).unwrap_or(false);\n        if !ok {\n            io.err(\"serve-question: --update payload needs an options array; nothing was delivered. Fix the payload and rerun --update on the same key.\\n\");\n            return 1;\n        }\n        if !is_alive(&qdir, &key) {\n            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\");\n            return 2;\n        }\n        let delivered = next_file(&qdir, &key);\n        let _ = std::fs::copy(jsp::resolve(&cwd, &[&pp]), &delivered);\n        touch_now(&delivered);\n        io.out(\"next round delivered; the page reloads itself\\n\");\n        return 0;\n    }","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/context/src/serve_question.rs#L279-L315","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the printed message for the underlying cause (path or JSON error) and fix accordingly.","Verify the payload exists relative to the cwd serve-question runs in; use an absolute path if unsure.","Validate the payload JSON parses (e.g. with a JSON linter) before re-running --update."],"exampleFix":"// before\nserve-question --update --key q-123 --payload ./round2.josn\n// after\nserve-question --update --key q-123 --payload /abs/path/round2.json","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst payloadPath = jspResolve(cwd, pp);\nJSON.parse(fs.readFileSync(payloadPath, 'utf8')); // throws early with a clear message","typeGuard":"const isReadableJson = (p) => { try { JSON.parse(require('fs').readFileSync(p, 'utf8')); return true; } catch { return false; } };","tryCatchPattern":"const res = spawnSync('serve-question', args);\nif (res.status === 1) {\n  const msg = res.stderr.trim();\n  if (msg.includes('No such file')) fixPath(); else if (msg.includes('parse')) fixJson();\n}","preventionTips":["Pre-validate the payload file exists and parses before invoking","Use absolute paths for --payload","Run serve-question from the same cwd used when the payload path was created"],"tags":["cli","file-read","json"],"backgroundTag":"file-read-failed","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}