{"record":{"id":"65d93ada6efcd532","repo":"nikivdev/code","slug":"docs-hub-dev-server-exited-with-error","errorCode":null,"errorMessage":"docs hub dev server exited with error","messagePattern":"docs hub dev server exited with error","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/docs.rs","lineNumber":597,"sourceCode":"        bail!(\"bun or npm is required to run docs hub dev server\");\n    };\n\n    let mut child = cmd\n        .current_dir(hub_root)\n        .stdout(std::process::Stdio::inherit())\n        .stderr(std::process::Stdio::inherit())\n        .spawn()\n        .context(\"failed to start docs hub dev server\")?;\n\n    if !no_open {\n        let url = format!(\"http://{}:{}\", host, port);\n        wait_for_port(host, port, std::time::Duration::from_secs(10));\n        open_in_browser(&url);\n    }\n\n    let status = child.wait().context(\"failed to wait on docs hub\")?;\n    if !status.success() {\n        bail!(\"docs hub dev server exited with error\");\n    }\n    Ok(())\n}\n\nfn start_docs_hub_daemon(hub_root: &Path, host: &str, port: u16) -> Result<()> {\n    let mut cmd = if which(\"bun\").is_ok() {\n        let port_arg = port.to_string();\n        let host_arg = host.to_string();\n        let mut cmd = Command::new(\"bun\");\n        cmd.args([\n            \"run\",\n            \"dev\",\n            \"--\",\n            \"--port\",\n            &port_arg,\n            \"--hostname\",\n            &host_arg,\n        ]);","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/docs.rs#L579-L615","documentation":"After spawning the docs hub dev server as a child process, run_docs_hub_dev waits on it and bails if the exit status is not success. This means the dev server process was started but terminated with a non-zero exit code — the crash happened inside bun/npm/Next.js, not in this library.","triggerScenarios":"Calling run_docs_hub when the spawned `bun dev` / `npm run dev` process fails at runtime: port already bound by another process, missing node_modules or broken install, syntax/config error in the hub app, or the user presses Ctrl-C (SIGINT yields non-success status).","commonSituations":"Port 4410 already in use by a previous hub instance; dependencies never installed (`bun install` skipped or failed silently); corrupted node_modules after an upgrade; terminating the command with Ctrl-C; Node version too old for the hub's framework.","solutions":["Read the child's stderr/stdout (they are inherited) for the real failure — e.g. EADDRINUSE — and free the port (`lsof -i :4410`, kill the stale process, or pass a different --port)","Run `bun install` (or `npm install`) in the hub root to fix missing/broken dependencies, then retry","Recreate the hub directory to get a clean template copy if the app itself is corrupted","If the non-zero status was just Ctrl-C, treat it as expected and re-run when needed"],"exampleFix":"// before\n$ mytool docs hub dev\nError: docs hub dev server exited with error\n  (stderr: Error: listen EADDRINUSE: 4410)\n// after\n$ lsof -ti :4410 | xargs kill\n$ mytool docs hub dev --port 4411","handlingStrategy":"retry","validationCode":"// pre-check the port before starting the dev server\nfn port_free(host: &str, port: u16) -> bool {\n    std::net::TcpListener::bind((host, port)).is_ok()\n}\nif !port_free(\"127.0.0.1\", 4410) {\n    eprintln!(\"port 4410 in use — stop the old hub or pass a different --port\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"match run_docs_hub(&opts) {\n    Err(e) if e.to_string().contains(\"docs hub dev server exited with error\") => {\n        eprintln!(\"dev server crashed; inspect inherited stderr (port in use? missing deps?) and retry\");\n        // retry once after bun install\n        let _ = std::process::Command::new(\"bun\").arg(\"install\").current_dir(&hub_root).status();\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Always run dependency install (ensure_docs_hub_deps) before starting the dev server","Pick a dedicated port and guard against stale processes holding it","Don't Ctrl-C during startup if you rely on exit status for orchestration","Keep Node/bun versions current for the hub's framework requirements"],"tags":["rust","process-exit","dev-server","port-conflict"],"backgroundTag":"process-exited-nonzero","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}