{"record":{"id":"5c09e3fd7f183aa3","repo":"nikivdev/code","slug":"failed-to-start-daemon","errorCode":null,"errorMessage":"failed to start daemon {}","messagePattern":"failed to start daemon (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/supervisor.rs","lineNumber":116,"sourceCode":"\npub fn ensure_running(boot: bool, announce: bool) -> Result<()> {\n    let socket_path = resolve_socket_path(None)?;\n    ensure_supervisor_running(&socket_path, announce, boot)?;\n    Ok(())\n}\n\npub fn ensure_daemon_running(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {\n    let socket_path = resolve_socket_path(None)?;\n    ensure_supervisor_running(&socket_path, announce, false)?;\n    let request = IpcRequest {\n        action: SupervisorIpcAction::StartDaemon {\n            name: name.to_string(),\n            config_path: config_path.map(|p| p.display().to_string()),\n        },\n    };\n    let response = send_request(&socket_path, &request)?;\n    if !response.ok {\n        bail!(\n            \"{}\",\n            response\n                .message\n                .unwrap_or_else(|| format!(\"failed to start daemon {}\", name))\n        );\n    }\n    if announce {\n        if let Some(message) = response.message {\n            println!(\"OK {}\", message);\n        }\n    }\n    Ok(())\n}\n\npub fn stop_daemon_managed(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {\n    let socket_path = resolve_socket_path(None)?;\n    ensure_supervisor_running(&socket_path, announce, false)?;\n    let request = IpcRequest {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/supervisor.rs#L98-L134","documentation":"ensure_daemon_running sends a start request to the supervisor daemon over its Unix socket and checks response.ok. When the response is not ok, it bails with the daemon's message if present, otherwise the generic \"failed to start daemon <name>\". This indicates the supervisor refused or failed to start the named daemon.","triggerScenarios":"Calling ensure_daemon_running when send_request succeeds at the IPC level but the returned response has ok == false and message == None — e.g. the daemon binary/config is invalid, the daemon crashed immediately on start, or the name doesn't match any configured daemon.","commonSituations":"Daemon config file has a syntax error or points to a missing binary; daemon name typo'd; daemon port already in use so the child exits at startup; supervisor lacks permissions to launch the process; stale supervisor state after an upgrade.","solutions":["Check the supervisor's logs/output for the daemon's startup error (the generic message means no detail was returned).","Verify the daemon's config path and that the executable it points to exists and is runnable.","Confirm the daemon name matches a configured daemon.","Restart the supervisor itself so it reloads configs and clears stale state, then retry."],"exampleFix":"// before\nmyapp supervisor start mydaemon\n// failed to start daemon mydaemon\n// after — check config first\nmyapp supervisor status            # inspect state\nmyapp daemon --config ./mydaemon.toml  # run in foreground to see the real error","handlingStrategy":"try-catch","validationCode":"// preflight: is the supervisor socket reachable?\nconst socket = '/tmp/myapp-supervisor.sock';\nif (!fs.existsSync(socket)) {\n  throw new Error(`Supervisor socket ${socket} missing; start the supervisor first.`);\n}","typeGuard":"type DaemonStartResponse = { ok: true } | { ok: false; message?: string };\nfunction startFailed(r: DaemonStartResponse): r is Extract<DaemonStartResponse, { ok: false }> {\n  return r.ok === false;\n}","tryCatchPattern":"try {\n  await supervisor.startDaemon('mydaemon');\n} catch (e) {\n  const msg = String(e);\n  if (msg.includes('failed to start daemon')) {\n    console.error('Supervisor refused to start the daemon. Check its config and logs;');\n    console.error('run the daemon in the foreground to see the startup error.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate daemon config files (paths, binaries, ports) before handing them to the supervisor.","Use unique, stable daemon names that match configuration.","Monitor the supervisor's log for child startup failures.","Ensure the daemon binary is executable and its ports are free."],"tags":["daemon","supervisor","ipc","process","unix-socket"],"backgroundTag":"daemon-start-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}