spacedriveapp/spacedrive · error · anyhow::Error

Daemon exited with error: {}

Error message

Daemon exited with error: {}

What it means

'sd start --foreground' runs sd-daemon as a child and waits on command.status(). The child exited with a non-zero ExitStatus, which this arm re-wraps. The daemon's own stderr is visible above the message in foreground mode and carries the root cause.

Source

Thrown at apps/cli/src/main.rs:303

			if let Some(ref inst) = instance {
				command.arg("--instance").arg(inst);
			}

			// Set working directory to current directory
			command.current_dir(std::env::current_dir()?);

			if foreground {
				// Foreground mode: inherit stdout/stderr so logs are visible
				println!("Starting daemon in foreground mode...");
				println!("Press Ctrl+C to stop the daemon");
				println!("═══════════════════════════════════════════════════════");

				match command.status() {
					Ok(status) => {
						if status.success() {
							println!("Daemon exited successfully");
						} else {
							return Err(anyhow::anyhow!("Daemon exited with error: {}", status));
						}
					}
					Err(e) => {
						return Err(anyhow::anyhow!("Failed to start daemon: {}", e));
					}
				}
			} else {
				// Background mode: redirect stdout/stderr to null
				command.stdout(std::process::Stdio::null());
				command.stderr(std::process::Stdio::null());

				match command.spawn() {
					Ok(child) => {
						println!("Daemon started (PID: {})", child.id());

						// Wait a moment for daemon to start up
						tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Read the daemon output printed above this error; it identifies the failing subsystem
  2. Check for a running daemon with 'sd status' and stop it before starting again
  3. Run the daemon directly with RUST_LOG=debug sd-daemon to get a full trace
  4. Verify ownership/permissions of the data directory
Defensive patterns

Strategy: try-catch

Validate before calling

#!/usr/bin/env bash
# Free the port before starting in foreground
port=6969
if ss -ltn "sport = :$port" | grep -q LISTEN; then
  sd stop || true
fi
sd start --foreground

Try / catch

match command.status() {
    Ok(status) if status.success() => println!("Daemon exited successfully"),
    Ok(status) => {
        // foreground mode already printed the daemon's own logs above us
        anyhow::bail!("Daemon exited with error: {} (check daemon output above or 'sd logs follow')", status)
    }
    Err(e) => anyhow::bail!("Failed to start daemon: {} (is sd-daemon next to sd and executable?)", e),
}

Prevention

When it happens

Trigger: Port 6969 (or the instance-derived port) already bound; corrupt or permission-denied data dir; database lock held by another process; daemon panic during init.

Common situations: Another daemon still running from an earlier session; stale lock files; first run after a perms change on the data directory.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/c1eba82ae34672c1. Report an issue: GitHub.