{"record":{"id":"27e69626603e731f","repo":"pbakaus/impeccable","slug":"serve-question","errorCode":null,"errorMessage":"serve-question: {}\n","messagePattern":"serve-question: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/serve_question.rs","lineNumber":409,"sourceCode":"    }\n\n    // ---- server (blocking or detached) ----\n    let raw = match &payload_path {\n        Some(pp) => match std::fs::read(jsp::resolve(&cwd, &[pp])) {\n            Ok(b) => String::from_utf8_lossy(&b).into_owned(),\n            Err(e) => {\n                io.err(&format!(\"Error: {}\\n\", crate::util::node_read_error(pp, &e)));\n                return 1;\n            }\n        },\n        None => io.stdin().to_string(),\n    };\n    let detached_key = if a.has(\"detached-serve\") { a.arg(\"key\") } else { None };\n    let state = Arc::new(Mutex::new(ServerState::new(cwd.clone(), qdir.clone(), detached_key.clone(), idle_grace_ms)));\n    {\n        let mut st = state.lock().unwrap();\n        if let Err(msg) = st.load_round(&raw) {\n            io.err(&format!(\"serve-question: {}\\n\", msg));\n            return 1;\n        }\n    }\n    let port = if port_arg.is_finite() && port_arg >= 0.0 { port_arg as u16 } else { 0 };\n    let server = match tiny_http::Server::http((\"127.0.0.1\", port)) {\n        Ok(s) => s,\n        Err(e) => {\n            io.err(&format!(\"Error: listen EADDRINUSE: {}\\n\", e));\n            return 1;\n        }\n    };\n    let actual_port = server.server_addr().to_ip().map(|a| a.port()).unwrap_or(port);\n    let url = format!(\"http://127.0.0.1:{}/\", actual_port);\n    if a.has(\"detached-serve\") {\n        let _ = std::fs::create_dir_all(&qdir);\n        let key = a.arg(\"key\").unwrap_or_default();\n        let st = json!({ \"pid\": std::process::id(), \"port\": actual_port, \"url\": url });\n        let _ = std::fs::write(state_file(&qdir, &key), json_compact(&st));","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/context/src/serve_question.rs#L391-L427","documentation":"The server state failed to load/validate the round payload (ServerState::load_round returned an error message). The command prints `serve-question: <msg>` and exits 1 before binding any port, meaning the payload did not parse or validate as a valid question round.","triggerScenarios":"`serve-question` is invoked with payload content (from --payload-path or stdin) that does not satisfy load_round: malformed JSON, missing required question fields, or a structurally invalid round document.","commonSituations":"Hand-edited or truncated payload files, piping the wrong content into stdin, an upstream tool emitting an unexpected payload schema, or reading an error page instead of the JSON payload.","solutions":["Read the printed <msg> for the specific field/format problem.","Validate the payload is well-formed JSON (e.g. `jq . payload.json`).","Regenerate the payload with the tool that produced it instead of editing by hand.","Ensure stdin actually contains the payload when no --payload-path is given (not shell echo of an empty string)."],"exampleFix":"// before\necho \"\" | impeccable serve-question\n// after\nimpeccable serve-question --payload-path ./question.json","handlingStrategy":"validation","validationCode":"// validate the payload parses as JSON before serving\nconst payload = JSON.parse(fs.readFileSync(payloadPath, 'utf8'));\nif (!payload || typeof payload !== 'object') throw new Error('invalid round payload');","typeGuard":"function isValidRoundPayload(p) {\n  return typeof p === 'object' && p !== null && !Array.isArray(p) && typeof p.question === 'string';\n}","tryCatchPattern":"try {\n  run('impeccable serve-question --payload-path q.json');\n} catch (e) {\n  if (e.stderr.startsWith('serve-question:')) console.error('payload rejected:', e.stderr);\n  throw e;\n}","preventionTips":["Generate payloads only via the producing tool, never by hand.","Run `jq . payload.json` as a smoke check before serving.","Never pipe empty or unrelated content on stdin when omitting --payload-path.","Pin the payload schema; re-validate after tool upgrades."],"tags":["validation","payload","json","cli"],"backgroundTag":"schema-validation-failed","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}