{"record":{"id":"89376af03108511e","repo":"tonhowtf/omniget","slug":"could-not-determine-data-directory-ytdlp","errorCode":null,"errorMessage":"Could not determine data directory","messagePattern":"Could not determine data directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/ytdlp.rs","lineNumber":1827,"sourceCode":"    } else {\n        \"yt-dlp\"\n    }\n}\n\nfn ytdlp_release_base(channel: YtdlpChannel) -> &'static str {\n    match channel {\n        YtdlpChannel::Stable => \"https://github.com/yt-dlp/yt-dlp/releases/latest/download\",\n        YtdlpChannel::Nightly => {\n            \"https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest/download\"\n        }\n    }\n}\n\nuse crate::core::dependencies::integrity;\n\nasync fn download_ytdlp_binary() -> anyhow::Result<PathBuf> {\n    let target =\n        managed_ytdlp_path().ok_or_else(|| anyhow!(\"Could not determine data directory\"))?;\n    download_ytdlp_asset(ytdlp_asset_name(), target).await\n}\n\n/// O asset `yt-dlp` da release é o zipapp universal (Python ≥ 3.10).\nconst YTDLP_ZIPAPP_ASSET: &str = \"yt-dlp\";\n\nasync fn download_ytdlp_zipapp() -> anyhow::Result<PathBuf> {\n    let target =\n        managed_ytdlp_zipapp_path().ok_or_else(|| anyhow!(\"Could not determine data directory\"))?;\n    download_ytdlp_asset(YTDLP_ZIPAPP_ASSET, target).await\n}\n\nasync fn download_ytdlp_asset(asset: &str, target: PathBuf) -> anyhow::Result<PathBuf> {\n    if let Some(parent) = target.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n\n    let channel = ytdlp_channel();","sourceCodeStart":1809,"sourceCodeEnd":1845,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/ytdlp.rs#L1809-L1845","documentation":"`download_ytdlp_binary` computes the target file path via `managed_ytdlp_path()`, which returns None when the app cannot resolve its data directory (e.g. no XDG dirs, no home directory, platform API failure). Rather than guessing a location, it fails with \"Could not determine data directory\". This is an environment-resolution failure, not a network issue.","triggerScenarios":"`managed_ytdlp_path()` returns None — typically because the OS data directory (XDG_DATA_HOME / app data dir) cannot be resolved in the current environment.","commonSituations":"Running in a minimal container/CI with no HOME set; headless Linux without xdg-user-dirs; restricted service accounts; unusual sandboxed environments that block directory APIs.","solutions":["Ensure HOME is set and points to a writable directory (export HOME=/path in the service/container).","Set XDG_DATA_HOME explicitly to a writable location.","Run the app as a user with a proper profile rather than a system/no-login account.","Inspect `managed_ytdlp_path()`/dirs crate usage to confirm which environment variable is missing and set it."],"exampleFix":"// before (CI/container)\ncargo test\n// after\nexport HOME=/tmp && export XDG_DATA_HOME=/tmp/.data\ncargo test","handlingStrategy":"validation","validationCode":"if std::env::var_os(\"HOME\").is_none() && std::env::var_os(\"XDG_DATA_HOME\").is_none() {\n    return Err(\"set HOME or XDG_DATA_HOME before running\");\n}","typeGuard":"fn data_dir_resolvable() -> bool {\n    std::env::var_os(\"XDG_DATA_HOME\").is_some() || std::env::var_os(\"HOME\").is_some()\n}","tryCatchPattern":"match ensure_ytdlp().await {\n    Err(e) if e.to_string().contains(\"Could not determine data directory\") => {\n        // fix environment (HOME/XDG_DATA_HOME) and retry\n    }\n    other => other?,\n}","preventionTips":["Always launch the app/service with HOME set.","Set XDG_DATA_HOME explicitly in containers and CI.","Avoid running under no-login system accounts without profiles."],"tags":["data-directory","environment","xdg","rust","config"],"backgroundTag":"missing-env-var","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}