{"record":{"id":"b31b3b2170c50cbf","repo":"sinelaw/fresh","slug":"server-error","errorCode":null,"errorMessage":"server error: {}","messagePattern":"server error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/main.rs","lineNumber":3689,"sourceCode":"        // client_handshake already printed the mismatch reason.\n        anyhow::bail!(\"handshake with the Fresh editor failed\");\n    }\n    Ok(CmdConnection { conn, reader })\n}\n\n/// Read control replies until a `ScriptResult` arrives (or an error/EOF/timeout).\n/// Returns `(ok, error, output)`.\nfn read_script_result(\n    conn: &mut CmdConnection,\n    timeout: std::time::Duration,\n) -> AnyhowResult<(bool, Option<String>, Option<String>)> {\n    use fresh::server::protocol::ServerControl;\n    loop {\n        match conn.recv_within(timeout)? {\n            Some(ServerControl::ScriptResult { ok, error, output }) => {\n                return Ok((ok, error, output))\n            }\n            Some(ServerControl::Error { message }) => anyhow::bail!(\"server error: {}\", message),\n            Some(_) => continue,\n            None => anyhow::bail!(\"server closed the connection before answering\"),\n        }\n    }\n}\n\n/// Dispatch a `--cmd cmd ...` / `--cmd split ...` / `--cmd workspace ...` /\n/// `--cmd agent ...` invocation against a running editor. `tokens` is the full\n/// `--cmd` vector (leading verb included).\nfn run_cmd_command(tokens: &[&str]) -> AnyhowResult<()> {\n    let (session, rest) = extract_session_flag(tokens);\n    let session = session.as_deref();\n\n    match rest.first().copied() {\n        Some(\"script\") => {\n            match &rest[1..] {\n                [\"run\", from @ ..] => script_run(session, from),\n                [\"check\", from @ ..] => script_check(from),","sourceCodeStart":3671,"sourceCodeEnd":3707,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/main.rs#L3671-L3707","documentation":"While waiting for a ScriptResult, the client received a ServerControl::Error frame from the editor. The message is wrapped as \"server error: <message>\" — the inner message is the editor-side failure for the command/script that was submitted.","triggerScenarios":"Any --cmd/--script submission where the editor-side handler errors: unknown command token, invalid arguments, a script that threw, or an operation rejected by the editor (e.g. command unavailable in the current state).","commonSituations":"Typo'd subcommand passed to --cmd; script using an API not present in the running editor; requesting a workspace/split operation that conflicts with current layout; agent tooling sending malformed commands.","solutions":["Read the inner message after \"server error:\" — it names the actual editor-side failure.","Fix the --cmd arguments or the throwing line in your script accordingly.","Confirm the command/feature exists in the running editor's version.","Retry after correcting; errors here are per-request, not connection-level."],"exampleFix":"// before\nfresh --cmd workspace togglee   # typo → server error: unknown command\n// after\nfresh --cmd workspace toggle","handlingStrategy":"try-catch","validationCode":"// validate --cmd tokens against known commands before sending\nconst KNOWN = ['split', 'workspace', 'agent', 'quit', 'ping'];\nconst cmd = process.argv[3];\nif (!KNOWN.includes(cmd)) { console.error(`unknown --cmd '${cmd}'; valid: ${KNOWN.join(', ')}`); process.exit(1); }","typeGuard":null,"tryCatchPattern":"// rust\nmatch read_control_reply(&mut conn, timeout) {\n    Ok((true, _, output)) => println!(\"{output}\"),\n    Ok((false, Some(err), _)) => { eprintln!(\"command rejected: {err}\"); std::process::exit(1); }\n    Err(e) if e.to_string().starts_with(\"server error\") => { eprintln!(\"fix cmd/script: {e}\"); std::process::exit(1); }\n    Err(e) => return Err(e),\n}","preventionTips":["Check --cmd spelling against the documented command list.","Keep scripts compatible with the running editor's API version.","Validate layout arguments (splits, workspace names) before submitting.","Treat the inner message as authoritative; fix that, not the wrapper text."],"tags":["cli","ipc","rpc","server-error"],"backgroundTag":"api-error-response","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}