{"record":{"id":"5c60f342497e475f","repo":"tonhowtf/omniget","slug":"cannot-determine-app-data-directory","errorCode":null,"errorMessage":"Cannot determine app data directory","messagePattern":"Cannot determine app data directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-cli/src/cookies.rs","lineNumber":78,"sourceCode":"            let cookie_str = cookies_for_domain\n                .iter()\n                .map(|(n, v)| format!(\"{}={}\", n, v))\n                .collect::<Vec<_>>()\n                .join(\"; \");\n            results.push((d, cookie_str));\n        }\n    }\n\n    results\n}\n\n/// Import a cookies.txt file into the app's cookie storage\npub fn import_cookies_file(src_path: &PathBuf, name: Option<&str>) -> Result<usize> {\n    let content = std::fs::read_to_string(src_path)\n        .with_context(|| format!(\"Failed to read {}\", src_path.display()))?;\n\n    let cookies_dir = app_data_dir()\n        .ok_or_else(|| anyhow::anyhow!(\"Cannot determine app data directory\"))?\n        .join(COOKIES_DIR);\n\n    std::fs::create_dir_all(&cookies_dir)?;\n\n    let dest_file = if let Some(n) = name {\n        cookies_dir.join(format!(\"cookies_{}.txt\", n))\n    } else {\n        cookies_dir.join(DEFAULT_COOKIE_FILE)\n    };\n\n    // Parse to validate and count\n    let parsed = parse_netscape_cookies(&content);\n    if parsed.is_empty() {\n        anyhow::bail!(\"No valid cookies found in file (expected Netscape format)\");\n    }\n\n    // Copy the raw file (preserving original format for yt-dlp consumption)\n    // Normalize line endings but otherwise keep as-is","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-cli/src/cookies.rs#L60-L96","documentation":"import_cookies_file needs the app data directory (via app_data_dir()) to locate the cookie storage folder. When the platform directories cannot be resolved (e.g. missing HOME/XDG env vars in headless or sandboxed environments), it returns this error instead of guessing a location.","triggerScenarios":"Calling import_cookies_file in an environment where app_data_dir() returns None — typically no HOME set, running as a system service, or a container without a writable home directory.","commonSituations":"CI jobs, systemd units, Docker containers, or SSH sessions without a proper HOME environment trying to import a cookies.txt file.","solutions":["Set the HOME environment variable to a writable directory before running the command.","Run the CLI as a normal user rather than a system account so platform dirs resolve.","In containers, create the expected app data dir and set HOME=/home/user with a writable volume."],"exampleFix":"// before\ncargo run -- import-cookies cookies.txt\n// after\nHOME=/home/user cargo run -- import-cookies cookies.txt","handlingStrategy":"try-catch","validationCode":"if (!process.env.HOME && process.platform !== 'win32') {\n  throw new Error('HOME must be set before importing cookies');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importCookiesFile(path, name);\n} catch (e) {\n  if (String(e).includes('Cannot determine app data directory')) {\n    process.env.HOME ||= '/tmp/apphome';\n    // retry once\n  } else throw e;\n}","preventionTips":["Ensure HOME (or USERPROFILE on Windows) is set in services and containers","Run the CLI as a regular user, not a system account","Smoke-test app data dir resolution in CI before cookie imports"],"tags":["filesystem","environment","cookies"],"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"}