{"record":{"id":"14e25477f3663823","repo":"t8y2/dbx","slug":"failed-to-create-data-dir","errorCode":null,"errorMessage":"Failed to create data dir","messagePattern":"Failed to create data dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-tauri/src/lib.rs","lineNumber":1497,"sourceCode":"            let setup_start = Instant::now();\n            eprintln!(\"[STARTUP] plugins registered in {:?}\", startup_begin.elapsed());\n            append_startup_probe(format!(\"setup entered after {:?}\", startup_begin.elapsed()));\n\n            if should_show_main_window_before_setup_tasks() {\n                prepare_main_window_for_display(app.handle());\n                show_main_window(app.handle());\n                append_startup_probe(format!(\n                    \"early main window show requested; {}\",\n                    main_window_probe_state(app.handle())\n                ));\n            }\n\n            append_startup_probe(\"resolving app data dir\");\n            let default_data_dir =\n                app.path().app_data_dir().map_err(|e| e.to_string()).expect(\"Failed to resolve app data dir\");\n            let data_dir_resolution = data_dir::resolve_data_dir_with_mode(default_data_dir);\n            let data_dir = data_dir_resolution.data_dir.clone();\n            std::fs::create_dir_all(&data_dir).expect(\"Failed to create data dir\");\n            let data_dir_mode = startup_data_dir_mode(&data_dir_resolution.mode);\n            append_startup_probe(format!(\"data dir ready mode={data_dir_mode}\"));\n            let alternative_data_dir = data_dir::alternative_data_dir(&data_dir_resolution);\n            match maybe_import_user_data_db(&data_dir, alternative_data_dir.as_deref()) {\n                Ok(result) => eprintln!(\"[STARTUP] data db fallback import: {result:?}\"),\n                Err(err) => eprintln!(\"[STARTUP] data db fallback import failed: {err}\"),\n            }\n            let db_path = data_dir.join(\"dbx.db\");\n\n            let t = Instant::now();\n            append_startup_probe(format!(\"opening storage file=dbx.db data_dir_mode={data_dir_mode}\"));\n            let storage = tauri::async_runtime::block_on(async {\n                let s = Storage::open(&db_path).await.expect(\"Failed to open storage\");\n                eprintln!(\"[STARTUP]   Storage::open in {:?}\", t.elapsed());\n                append_startup_probe(format!(\"storage opened in {:?}\", t.elapsed()));\n                let t2 = Instant::now();\n                s.migrate_from_json(&data_dir).await.expect(\"Failed to migrate JSON data\");\n                eprintln!(\"[STARTUP]   migrate_from_json in {:?}\", t2.elapsed());","sourceCodeStart":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/src-tauri/src/lib.rs#L1479-L1515","documentation":"After resolving the data directory, the app calls std::fs::create_dir_all(&data_dir) to ensure the directory exists, panicking with this message if the OS refuses. create_dir_all fails only on permission problems, path issues, or I/O errors (read-only filesystem, disk full), not because parents are missing.","triggerScenarios":"std::fs::create_dir_all(&data_dir) at lib.rs:1497 failing with PermissionDenied (no write access to the parent), AlreadyFile (a file exists at the data-dir path), or errors like ENOSPC/EROFS.","commonSituations":"A regular file already exists where the data dir should be (leftover corrupted install); running from a read-only mount or read-only home; enterprise-managed machines denying writes to the profile directory; full disk.","solutions":["Check whether a file occupies the data-dir path and remove/rename it so the directory can be created.","Run the app under an account with write permission to the data directory, or configure a writable data dir via the app's data-dir mode/fallback.","Free disk space or remount the volume read-write; surface the underlying io::Error instead of expect() to diagnose."],"exampleFix":"// before\nstd::fs::create_dir_all(&data_dir).expect(\"Failed to create data dir\");\n// after\nif let Err(e) = std::fs::create_dir_all(&data_dir) {\n    eprintln!(\"[STARTUP] create_dir_all({data_dir:?}) failed: {e}\");\n    return Err(format!(\"data dir creation failed: {e}\"));\n}","handlingStrategy":"validation","validationCode":"// Rust: preflight checks before create_dir_all\nfn can_create_dir(path: &std::path::Path) -> Result<(), String> {\n    if path.is_file() {\n        return Err(format!(\"{} exists as a file\", path.display()));\n    }\n    let parent = path.parent().unwrap_or(path);\n    if !parent.exists() || std::fs::metadata(parent)?.permissions().readonly() {\n        return Err(format!(\"parent {} not writable\", parent.display()));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"std::fs::create_dir_all(&data_dir)\n    .map_err(|e| format!(\"create_dir_all({}): {e}\", data_dir.display()))?;","preventionTips":["Check that the data-dir path is not occupied by a regular file before creating.","Ensure the app runs with write permission to the chosen data location.","Monitor free disk space; handle EROFS/ENOSPC explicitly."],"tags":["rust","filesystem","permissions","startup"],"backgroundTag":"directory-creation-permission-denied","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}