{"record":{"id":"e592cff9ceb44545","repo":"sinelaw/fresh","slug":"could-not-determine-data-directory-dir","errorCode":null,"errorMessage":"Could not determine data directory","messagePattern":"Could not determine data directory","errorType":"exception","errorClass":"io::Error (NotFound)","httpStatus":null,"severity":"error","filePath":"crates/fresh-editor-core/src/data_dir.rs","lineNumber":55,"sourceCode":"/// the override has to move with it.\n///\n/// Test-only hook: production never calls this, and with no override installed\n/// this costs one thread-local read per lookup. It is `#[doc(hidden)] pub`\n/// rather than `#[cfg(test)]` because `#[cfg(test)]` in `fresh-editor-core` is\n/// invisible to the integration tests in `fresh-editor` (see CONTRIBUTING,\n/// \"The data layer is its own crate\").\n#[doc(hidden)]\npub fn set_data_dir_override(dir: Option<PathBuf>) -> Option<PathBuf> {\n    DATA_DIR_OVERRIDE.with(|slot| std::mem::replace(&mut *slot.borrow_mut(), dir))\n}\n\n/// The `fresh` data directory (`$XDG_DATA_HOME/fresh`, or the platform equivalent).\npub fn get_data_dir() -> std::io::Result<PathBuf> {\n    if let Some(dir) = DATA_DIR_OVERRIDE.with(|slot| slot.borrow().clone()) {\n        return Ok(dir);\n    }\n    let data_dir = dirs::data_dir().ok_or_else(|| {\n        std::io::Error::new(\n            std::io::ErrorKind::NotFound,\n            \"Could not determine data directory\",\n        )\n    })?;\n    Ok(data_dir.join(\"fresh\"))\n}\n","sourceCodeStart":37,"sourceCodeEnd":62,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/data_dir.rs#L37-L62","documentation":"get_data_dir() fails when the OS data directory cannot be determined via dirs::data_dir(). Unless a test override (DATA_DIR_OVERRIDE) is installed, the function must resolve the platform data dir to build `$XDG_DATA_HOME/fresh`. This is the standalone data-dir resolver used throughout the editor.","triggerScenarios":"Calling get_data_dir() with DATA_DIR_OVERRIDE unset and dirs::data_dir() returning None (no XDG_DATA_HOME, no HOME, or non-standard platform).","commonSituations":"CI runners or containers with HOME unset; integration tests that forgot to set the override and run in a bare environment.","solutions":["Set XDG_DATA_HOME or HOME in the environment.","In tests, install DATA_DIR_OVERRIDE (thread-local override) to a tempdir before calling get_data_dir().","Fix the service/container definition to provide a writable home."],"exampleFix":"// before\nlet dir = get_data_dir()?;\n// after\nDATA_DIR_OVERRIDE.with(|s| *s.borrow_mut() = Some(tempdir.path().to_path_buf()));\nlet dir = get_data_dir()?;","handlingStrategy":"try-catch","validationCode":"if dirs::data_dir().is_none() {\n    eprintln!(\"no data dir resolvable; set XDG_DATA_HOME or override in test\");\n}","typeGuard":null,"tryCatchPattern":"match get_data_dir() {\n    Ok(dir) => dir,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        let tmp = std::env::temp_dir().join(\"fresh-fallback\");\n        std::fs::create_dir_all(&tmp)?;\n        tmp\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Install DATA_DIR_OVERRIDE in tests pointing at a tempdir","Set XDG_DATA_HOME in CI runners","Avoid calling get_data_dir before environment setup"],"tags":["environment","directories","io"],"backgroundTag":"missing-env-var","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}