nikivdev/code · error · anyhow::Error

failed to start daemon {}

Error message

failed to start daemon {}

What it means

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.

Source

Thrown at src/supervisor.rs:116

pub fn ensure_running(boot: bool, announce: bool) -> Result<()> {
    let socket_path = resolve_socket_path(None)?;
    ensure_supervisor_running(&socket_path, announce, boot)?;
    Ok(())
}

pub fn ensure_daemon_running(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {
    let socket_path = resolve_socket_path(None)?;
    ensure_supervisor_running(&socket_path, announce, false)?;
    let request = IpcRequest {
        action: SupervisorIpcAction::StartDaemon {
            name: name.to_string(),
            config_path: config_path.map(|p| p.display().to_string()),
        },
    };
    let response = send_request(&socket_path, &request)?;
    if !response.ok {
        bail!(
            "{}",
            response
                .message
                .unwrap_or_else(|| format!("failed to start daemon {}", name))
        );
    }
    if announce {
        if let Some(message) = response.message {
            println!("OK {}", message);
        }
    }
    Ok(())
}

pub fn stop_daemon_managed(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {
    let socket_path = resolve_socket_path(None)?;
    ensure_supervisor_running(&socket_path, announce, false)?;
    let request = IpcRequest {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Check the supervisor's logs/output for the daemon's startup error (the generic message means no detail was returned).
  2. Verify the daemon's config path and that the executable it points to exists and is runnable.
  3. Confirm the daemon name matches a configured daemon.
  4. Restart the supervisor itself so it reloads configs and clears stale state, then retry.

Example fix

// before
myapp supervisor start mydaemon
// failed to start daemon mydaemon
// after — check config first
myapp supervisor status            # inspect state
myapp daemon --config ./mydaemon.toml  # run in foreground to see the real error
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: is the supervisor socket reachable?
const socket = '/tmp/myapp-supervisor.sock';
if (!fs.existsSync(socket)) {
  throw new Error(`Supervisor socket ${socket} missing; start the supervisor first.`);
}

Type guard

type DaemonStartResponse = { ok: true } | { ok: false; message?: string };
function startFailed(r: DaemonStartResponse): r is Extract<DaemonStartResponse, { ok: false }> {
  return r.ok === false;
}

Try / catch

try {
  await supervisor.startDaemon('mydaemon');
} catch (e) {
  const msg = String(e);
  if (msg.includes('failed to start daemon')) {
    console.error('Supervisor refused to start the daemon. Check its config and logs;');
    console.error('run the daemon in the foreground to see the startup error.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/5c09e3fd7f183aa3. Report an issue: GitHub.