{"record":{"id":"c1eba82ae34672c1","repo":"spacedriveapp/spacedrive","slug":"daemon-exited-with-error","errorCode":null,"errorMessage":"Daemon exited with error: {}","messagePattern":"Daemon exited with error: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/main.rs","lineNumber":303,"sourceCode":"\t\t\tif let Some(ref inst) = instance {\n\t\t\t\tcommand.arg(\"--instance\").arg(inst);\n\t\t\t}\n\n\t\t\t// Set working directory to current directory\n\t\t\tcommand.current_dir(std::env::current_dir()?);\n\n\t\t\tif foreground {\n\t\t\t\t// Foreground mode: inherit stdout/stderr so logs are visible\n\t\t\t\tprintln!(\"Starting daemon in foreground mode...\");\n\t\t\t\tprintln!(\"Press Ctrl+C to stop the daemon\");\n\t\t\t\tprintln!(\"═══════════════════════════════════════════════════════\");\n\n\t\t\t\tmatch command.status() {\n\t\t\t\t\tOk(status) => {\n\t\t\t\t\t\tif status.success() {\n\t\t\t\t\t\t\tprintln!(\"Daemon exited successfully\");\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn Err(anyhow::anyhow!(\"Daemon exited with error: {}\", status));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tErr(e) => {\n\t\t\t\t\t\treturn Err(anyhow::anyhow!(\"Failed to start daemon: {}\", e));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Background mode: redirect stdout/stderr to null\n\t\t\t\tcommand.stdout(std::process::Stdio::null());\n\t\t\t\tcommand.stderr(std::process::Stdio::null());\n\n\t\t\t\tmatch command.spawn() {\n\t\t\t\t\tOk(child) => {\n\t\t\t\t\t\tprintln!(\"Daemon started (PID: {})\", child.id());\n\n\t\t\t\t\t\t// Wait a moment for daemon to start up\n\t\t\t\t\t\ttokio::time::sleep(tokio::time::Duration::from_millis(500)).await;\n","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/main.rs#L285-L321","documentation":"'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.","triggerScenarios":"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.","commonSituations":"Another daemon still running from an earlier session; stale lock files; first run after a perms change on the data directory.","solutions":["Read the daemon output printed above this error; it identifies the failing subsystem","Check for a running daemon with 'sd status' and stop it before starting again","Run the daemon directly with RUST_LOG=debug sd-daemon to get a full trace","Verify ownership/permissions of the data directory"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"#!/usr/bin/env bash\n# Free the port before starting in foreground\nport=6969\nif ss -ltn \"sport = :$port\" | grep -q LISTEN; then\n  sd stop || true\nfi\nsd start --foreground","typeGuard":null,"tryCatchPattern":"match command.status() {\n    Ok(status) if status.success() => println!(\"Daemon exited successfully\"),\n    Ok(status) => {\n        // foreground mode already printed the daemon's own logs above us\n        anyhow::bail!(\"Daemon exited with error: {} (check daemon output above or 'sd logs follow')\", status)\n    }\n    Err(e) => anyhow::bail!(\"Failed to start daemon: {} (is sd-daemon next to sd and executable?)\", e),\n}","preventionTips":["Always start foreground once after installs or updates to surface init errors","Keep RUST_LOG available and point users at 'sd logs follow' for the root cause","Check for an existing listener on port 6969 (or the instance port) before starting"],"tags":["cli","daemon","process","startup"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}