{"record":{"id":"4e46bd9b5253ef00","repo":"spacedriveapp/spacedrive","slug":"data-dir-must-be-set-in-production","errorCode":null,"errorMessage":"DATA_DIR must be set in production","messagePattern":"DATA_DIR must be set in production","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"apps/server/src/main.rs","lineNumber":403,"sourceCode":"\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n\t// Initialize logging\n\ttracing_subscriber::fmt()\n\t\t.with_env_filter(\n\t\t\ttracing_subscriber::EnvFilter::try_from_default_env()\n\t\t\t\t.unwrap_or_else(|_| \"info,sd_core=debug,sd_server=debug\".into()),\n\t\t)\n\t\t.init();\n\n\tlet args = Args::parse();\n\n\t// Resolve data directory\n\tlet base_data_dir = args.data_dir.unwrap_or_else(|| {\n\t\t#[cfg(not(debug_assertions))]\n\t\t{\n\t\t\tstd::env::var(\"DATA_DIR\")\n\t\t\t\t.expect(\"DATA_DIR must be set in production\")\n\t\t\t\t.into()\n\t\t}\n\t\t#[cfg(debug_assertions)]\n\t\t{\n\t\t\t// Default to `~/.spacedrive` in dev — matches the Tauri desktop app,\n\t\t\t// so `just dev-server` and `just dev-desktop` share libraries and\n\t\t\t// data persists between runs. Falls back to a tempdir only if the\n\t\t\t// home directory can't be resolved.\n\t\t\tstd::env::var(\"DATA_DIR\")\n\t\t\t\t.map(PathBuf::from)\n\t\t\t\t.or_else(|_| {\n\t\t\t\t\tdirs::home_dir()\n\t\t\t\t\t\t.map(|h| h.join(\".spacedrive\"))\n\t\t\t\t\t\t.ok_or(())\n\t\t\t\t})\n\t\t\t\t.unwrap_or_else(|_| {\n\t\t\t\t\twarn!(\"Could not resolve home directory; falling back to tempdir\");\n\t\t\t\t\tlet temp = tempfile::tempdir().expect(\"Failed to create temp dir\");","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/server/src/main.rs#L385-L421","documentation":"The sd-server binary resolves its data directory from the --data-dir flag, then the DATA_DIR env var. In release builds (not(debug_assertions)) the expect panics when neither is provided; debug builds fall back to ~/.spacedrive so dev workflows share data with the desktop app. This is an intentional fail-fast so a production server never silently writes state to an unpredictable working directory.","triggerScenarios":"Running the release binary in a container or systemd service without DATA_DIR; docker run missing -e DATA_DIR; systemd unit missing Environment=; wrapping the binary in a launcher script that drops the environment.","commonSituations":"First containerized deployment of the server; CI smoke tests using the release build; Nomad/Kubernetes pods without the env var in the spec.","solutions":["Set DATA_DIR=/var/lib/spacedrive (or your persisted volume path) when running the release server","Or pass --data-dir /path explicitly on the command line","In containers, mount a volume at that path so data survives restarts","For local debugging only, use a debug build, which defaults to ~/.spacedrive"],"exampleFix":"# before: release server started bare\n$ ./sd-server\nthread 'main' panicked: DATA_DIR must be set in production\n\n# after: explicit data directory\n$ DATA_DIR=/var/lib/spacedrive ./sd-server\n# or\n$ ./sd-server --data-dir /var/lib/spacedrive","handlingStrategy":"validation","validationCode":"// Before starting the release server, assert a data dir is resolved\nlet data_dir = args.data_dir.clone().or_else(|| std::env::var(\"DATA_DIR\").ok().map(PathBuf::from));\nlet Some(data_dir) = data_dir else {\n    eprintln!(\"DATA_DIR or --data-dir is required in production\");\n    std::process::exit(2);\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake DATA_DIR into container images and systemd units explicitly","Mount a persistent volume at DATA_DIR so restarts keep state","Add a startup preflight check in deployment scripts"],"tags":["configuration","environment","deployment","server"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}