{"record":{"id":"411c3ef79790b0d6","repo":"pkgxdev/pkgx","slug":"could-not-determine-data-directory","errorCode":null,"errorMessage":"Could not determine data directory","messagePattern":"Could not determine data directory","errorType":"error_code","errorClass":"io::Error (NotFound)","httpStatus":null,"severity":"error","filePath":"crates/lib/src/config.rs","lineNumber":97,"sourceCode":"\n    let default = dirs_next::home_dir().map(|x| x.join(\".pkgx\"));\n\n    if default.clone().is_some_and(|x| x.exists()) {\n        Ok(default.unwrap())\n    } else if let Ok(xdg) = env::var(\"XDG_DATA_HOME\") {\n        Ok(PathBuf::from(xdg).join(\"pkgx\"))\n    } else {\n        Ok(default.unwrap())\n    }\n}\n\nfn get_pantry_db_file() -> io::Result<PathBuf> {\n    if let Some(path) = get_PKGX_PANTRY_DIR() {\n        Ok(path.join(\"pantry.2.db\"))\n    } else if let Some(path) = dirs_next::cache_dir() {\n        Ok(path.join(\"pkgx/pantry.2.db\"))\n    } else {\n        Err(io::Error::new(\n            io::ErrorKind::NotFound,\n            \"Could not determine data directory\",\n        ))\n    }\n}\n","sourceCodeStart":79,"sourceCodeEnd":103,"githubUrl":"https://github.com/pkgxdev/pkgx/blob/6de1d7e953b98061f69db95d4bd45a2a6ee5d7da/crates/lib/src/config.rs#L79-L103","documentation":"`get_pantry_db_file` locates the pantry SQLite database: `PKGX_PANTRY_DIR` env var first, else `dirs_next::cache_dir()` joined with pkgx/pantry.2.db. When neither is resolvable it returns a NotFound io::Error 'Could not determine data directory'. Note the message mismatch (it checks the *cache* dir but reports the *data* directory), which is cosmetic — the failure mode is identical to the pantry-dir case.","triggerScenarios":"`Config::new()` on a system where `dirs_next::cache_dir()` returns None (no HOME / XDG_CACHE_HOME, headless service or container without a resolvable user cache dir) and PKGX_PANTRY_DIR is unset.","commonSituations":"Same as the cache-directory error: cron jobs, systemd services, Docker containers, or CI runners with a scrubbed environment; also macOS/Windows edge cases where the dirs crate cannot locate the cache dir.","solutions":["Set PKGX_PANTRY_DIR to an absolute path so the env-var branch is used","Set HOME or XDG_CACHE_HOME so dirs_next::cache_dir() resolves","Ensure the process runs as a user with a valid home directory entry"],"exampleFix":"// before (CI step)\n- run: pkgx install +openssl.org\n// after\n- run: |\n    export XDG_CACHE_HOME=$PWD/.cache\n    pkgx install +openssl.org","handlingStrategy":"fallback","validationCode":"fn pantry_db_resolvable() -> bool {\n    std::env::var(\"PKGX_PANTRY_DIR\").is_ok()\n        || dirs_next::cache_dir().is_some()\n}","typeGuard":null,"tryCatchPattern":"match Config::new() {\n    Err(e) if e.to_string() == \"Could not determine data directory\" => {\n        std::env::set_var(\"PKGX_PANTRY_DIR\", \"/var/cache/pkgx/pantry\");\n        Config::new()? // retry with explicit dir\n    }\n    other => other,\n}","preventionTips":["Set XDG_CACHE_HOME or HOME in headless environments","Set PKGX_PANTRY_DIR explicitly where the cache dir may be unavailable","Mirror the environment fixes used for the pantry dir error — both fail together","Validate the runtime environment in entrypoint scripts before invoking the library"],"tags":["config","environment","cache","xdg"],"backgroundTag":"missing-env-var","analyzedSha":"6de1d7e953b98061f69db95d4bd45a2a6ee5d7da","analyzedAt":"2026-09-10T09:59:03.886Z","contentChangedAt":"2026-09-10T09:59:03.886Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}