{"record":{"id":"b1ef195b32884d49","repo":"sinelaw/fresh","slug":"could-not-determine-data-directory","errorCode":null,"errorMessage":"Could not determine data directory","messagePattern":"Could not determine data directory","errorType":"exception","errorClass":"io::Error (NotFound)","httpStatus":null,"severity":"critical","filePath":"crates/fresh-editor-core/src/config_io.rs","lineNumber":1058,"sourceCode":"    pub config_dir: std::path::PathBuf,\n\n    /// User's home directory (for file open dialog shortcuts)\n    pub home_dir: Option<std::path::PathBuf>,\n\n    /// User's documents directory (for file open dialog shortcuts)\n    pub documents_dir: Option<std::path::PathBuf>,\n\n    /// User's downloads directory (for file open dialog shortcuts)\n    pub downloads_dir: Option<std::path::PathBuf>,\n}\n\nimpl DirectoryContext {\n    /// Create a DirectoryContext from the system directories\n    /// This should ONLY be called from main()\n    pub fn from_system() -> std::io::Result<Self> {\n        let data_dir = dirs::data_dir()\n            .ok_or_else(|| {\n                std::io::Error::new(\n                    std::io::ErrorKind::NotFound,\n                    \"Could not determine data directory\",\n                )\n            })?\n            .join(\"fresh\");\n\n        let config_dir = Self::default_config_dir().ok_or_else(|| {\n            std::io::Error::new(\n                std::io::ErrorKind::NotFound,\n                \"Could not determine config directory\",\n            )\n        })?;\n\n        Ok(Self {\n            data_dir,\n            config_dir,\n            home_dir: dirs::home_dir(),\n            documents_dir: dirs::document_dir(),","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/config_io.rs#L1040-L1076","documentation":"DirectoryContext::from_system fails when the `dirs` crate cannot locate the OS user data directory (e.g. XDG_DATA_HOME / ~/Library/Application Support / %APPDATA%). The library throws this in main()-time initialization because it cannot build its data directory path. It indicates an environment problem, not a code bug.","triggerScenarios":"Calling DirectoryContext::from_system() on a system where dirs::data_dir() returns None: missing XDG_DATA_HOME with no resolvable home directory, or running under a stripped environment (cron, systemd service, container) where $HOME is unset.","commonSituations":"Running the editor as a system service without HOME set; launching from a minimal Docker image; SSH into a system with no passwd entry for the user.","solutions":["Set XDG_DATA_HOME (or $HOME) in the environment before launching the editor.","For services, use Environment=HOME=/home/user or an EnvFile in the systemd unit.","Ensure the user has a valid passwd entry (check `getent passwd $(whoami)`)."],"exampleFix":"// before\nDirectoryContext::from_system()?;\n// after\nstd::env::set_var(\"XDG_DATA_HOME\", \"/tmp/app-data\"); // or ensure HOME is set in the service unit\nDirectoryContext::from_system()?;","handlingStrategy":"fallback","validationCode":"if std::env::var(\"XDG_DATA_HOME\").is_err() && std::env::var(\"HOME\").is_err() {\n    eprintln!(\"HOME/XDG_DATA_HOME unset; data directory cannot be resolved\");\n}","typeGuard":null,"tryCatchPattern":"match DirectoryContext::from_system() {\n    Ok(ctx) => ctx,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        std::env::set_var(\"XDG_DATA_HOME\", \"/tmp/fresh-data\");\n        DirectoryContext::from_system().expect(\"fallback data dir\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always launch with HOME or XDG_DATA_HOME set","Set environment explicitly in service/container definitions","Fail fast at startup with a clear message if the env is missing"],"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-16T04:17:20.429Z"}