{"record":{"id":"0959d6da61296117","repo":"sinelaw/fresh","slug":"server-error-main","errorCode":null,"errorMessage":"Server error: {}","messagePattern":"Server error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/main.rs","lineNumber":3369,"sourceCode":"    let response = read_reply()?\n        .ok_or_else(|| anyhow::anyhow!(\"Server closed connection during handshake\"))?;\n\n    match serde_json::from_str::<ServerControl>(&response)? {\n        ServerControl::Hello(server_hello) => {\n            if server_hello.protocol_version != PROTOCOL_VERSION {\n                eprintln!(\n                    \"Version mismatch: server is v{}\",\n                    server_hello.server_version\n                );\n                return Ok(false);\n            }\n            Ok(true)\n        }\n        ServerControl::VersionMismatch(mismatch) => {\n            eprintln!(\"Version mismatch: server is v{}\", mismatch.server_version);\n            Ok(false)\n        }\n        ServerControl::Error { message } => Err(anyhow::anyhow!(\"Server error: {}\", message)),\n        _ => Err(anyhow::anyhow!(\"Unexpected server response\")),\n    }\n}\n\n/// When launched from inside Fresh's own embedded terminal, forward the\n/// file/dir arguments to the parent editor (identified by `FRESH_SESSION`)\n/// instead of starting a second editor in the terminal.\n///\n/// Returns:\n/// - `Some(Ok(()))` — forwarded; the caller should exit.\n/// - `None` — not a nested launch, nothing to forward, or the parent\n///   socket is unreachable; the caller should launch inline as usual.\nfn try_forward_nested(args: &Args) -> Option<AnyhowResult<()>> {\n    // Only plain interactive file/dir opens are forwarded. Subcommands,\n    // --server and --attach are already handled before we get here;\n    // --stdin pipes content into a real editor and can't be forwarded.\n    if args.server || args.attach || args.stdin || args.files.is_empty() {\n        return None;","sourceCodeStart":3351,"sourceCodeEnd":3387,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/main.rs#L3351-L3387","documentation":"During the CLI handshake in main.rs, the server replied with the `ServerControl::Error { message }` variant. Fresh forwards the server's own error text verbatim via `\"Server error: {}\"`, so the root cause is whatever the editor reported (bad session, rejected command, internal failure). The CLI cannot proceed past the handshake when the server rejects it.","triggerScenarios":"Any handshake where the connected editor responds to the client Hello with `ServerControl::Error`; the message embedded in the error is produced server-side.","commonSituations":"Requesting an operation the running editor rejects; server hit an internal error while setting up the session; protocol accepted but the requested session/file failed validation on the server.","solutions":["Read the embedded message after 'Server error:' — it is the editor's own diagnostic and names the real problem.","Check the editor's logs for the matching server-side error to get the stack/cause.","Retry the same CLI command after fixing whatever the embedded message indicates.","If the message indicates a protocol/feature issue, upgrade client and editor to matching versions."],"exampleFix":"// before: treating the wrapper as the cause\nmatch result { Err(e) => eprintln!(\"failed: {e}\"), ... }\n// after: surface the inner server message for tooling\nif let Some(msg) = e.to_string().strip_prefix(\"Server error: \") {\n    eprintln!(\"editor rejected request: {msg}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_handshake() {\n    Err(e) if e.to_string().starts_with(\"Server error: \") => {\n        let detail = &e.to_string()[\"Server error: \".len()..];\n        eprintln!(\"editor rejected: {detail}\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Always surface the embedded message rather than only the wrapper text","Check editor logs when a handshake reports a server-side error","Validate requested files/sessions exist before sending the Hello","Keep client and server versions aligned"],"tags":["ipc","handshake","server-error","cli"],"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-16T04:17:20.429Z"}