{"record":{"id":"50bd2ae8b14de445","repo":"t8y2/dbx","slug":"failed-to-create-data-directory","errorCode":null,"errorMessage":"Failed to create data directory","messagePattern":"Failed to create data directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/dbx-web/src/main.rs","lineNumber":300,"sourceCode":"}\n\n#[tokio::main]\nasync fn main() {\n    tracing_subscriber::fmt()\n        .with_env_filter(\n            tracing_subscriber::EnvFilter::try_from_default_env()\n                .unwrap_or_else(|_| \"dbx_web=info,tower_http=info\".parse().unwrap()),\n        )\n        .init();\n\n    rustls::crypto::aws_lc_rs::default_provider().install_default().expect(\"Failed to install rustls crypto provider\");\n\n    // Data directory\n    let data_dir = std::env::var(\"DBX_DATA_DIR\").map(std::path::PathBuf::from).unwrap_or_else(|_| {\n        let home = std::env::var(\"HOME\").unwrap_or_else(|_| \".\".to_string());\n        std::path::PathBuf::from(home).join(\".dbx-web\")\n    });\n    std::fs::create_dir_all(&data_dir).expect(\"Failed to create data directory\");\n\n    let app_state = {\n        let db_path = data_dir.join(\"dbx.db\");\n        let storage = Storage::open(&db_path).await.expect(\"Failed to open storage\");\n        storage.migrate_from_json(&data_dir).await.expect(\"Failed to migrate JSON data\");\n\n        // Initialize core dialect registry and load external plugin dialects\n        register_core_dialects();\n        let registry = DialectRegistry::global();\n        let plugin_dirs = vec![data_dir.join(\"plugins\").join(\"dialects\")];\n        let load_result = DialectPluginLoader::scan_and_load(registry, &plugin_dirs);\n        log::info!(\n            \"Dialect plugins loaded: {} success, {} errors, {} skipped\",\n            load_result.loaded.len(),\n            load_result.errors.len(),\n            load_result.skipped.len()\n        );\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-web/src/main.rs#L282-L318","documentation":"On startup dbx-web resolves its data directory (DBX_DATA_DIR or ~/.dbx-web) and calls std::fs::create_dir_all with expect(). If the directory cannot be created, the process panics before serving any traffic.","triggerScenarios":"std::fs::create_dir_all(&data_dir) fails due to missing write permission on the parent, a file existing at the data_dir path, a read-only filesystem, or an invalid HOME/DBX_DATA_DIR path.","commonSituations":"Running in a container with a read-only root filesystem and no DBX_DATA_DIR volume; HOME pointing to a non-writable path; data_dir path occupied by a regular file; Docker/Kubernetes volume mounted with wrong ownership.","solutions":["Set DBX_DATA_DIR to a writable directory the process user can create and write.","Ensure the path is not occupied by a file and the parent directory is writable (check permissions/ownership).","In containers, mount a writable volume at the data directory (e.g., docker -v dbx-data:/data -e DBX_DATA_DIR=/data).","Replace expect() with graceful error handling that logs the OS error and exits with a clear message."],"exampleFix":"// before\nstd::fs::create_dir_all(&data_dir).expect(\"Failed to create data directory\");\n// after\nif let Err(e) = std::fs::create_dir_all(&data_dir) {\n    eprintln!(\"Failed to create data directory {}: {e}\", data_dir.display());\n    std::process::exit(1);\n}","handlingStrategy":"validation","validationCode":"fn data_dir_writable(path: &std::path::Path) -> bool {\n    if path.is_file() { return false; }\n    std::fs::create_dir_all(path)\n        .and_then(|_| std::fs::write(path.join(\".write_test\"), b\"ok\"))\n        .map(|_| true)\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"// match on the fs result and exit with a clear message\nif let Err(e) = std::fs::create_dir_all(&data_dir) {\n    eprintln!(\"Failed to create data directory {}: {e}\", data_dir.display());\n    std::process::exit(1);\n}","preventionTips":["Set DBX_DATA_DIR explicitly to a writable path in containers/deployments.","Mount a persistent writable volume at the data directory.","Verify the path is not a regular file and the user has write permission before launch.","Health-check disk writability as part of container startup."],"tags":["filesystem","rust","permissions","startup"],"backgroundTag":"directory-creation-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}