tonhowtf/omniget · error

Cannot determine app data directory

Error message

Cannot determine app data directory

What it means

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.

Solutions

  1. Set the HOME environment variable to a writable directory before running the command.
  2. Run the CLI as a normal user rather than a system account so platform dirs resolve.
  3. In containers, create the expected app data dir and set HOME=/home/user with a writable volume.

Example fix

// before
cargo run -- import-cookies cookies.txt
// after
HOME=/home/user cargo run -- import-cookies cookies.txt
Defensive patterns

Strategy: try-catch

Validate before calling

if (!process.env.HOME && process.platform !== 'win32') {
  throw new Error('HOME must be set before importing cookies');
}

Try / catch

try {
  await importCookiesFile(path, name);
} catch (e) {
  if (String(e).includes('Cannot determine app data directory')) {
    process.env.HOME ||= '/tmp/apphome';
    // retry once
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: CI jobs, systemd units, Docker containers, or SSH sessions without a proper HOME environment trying to import a cookies.txt file.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/5c60f342497e475f. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-cli/src/cookies.rs:78

            let cookie_str = cookies_for_domain
                .iter()
                .map(|(n, v)| format!("{}={}", n, v))
                .collect::<Vec<_>>()
                .join("; ");
            results.push((d, cookie_str));
        }
    }

    results
}

/// Import a cookies.txt file into the app's cookie storage
pub fn import_cookies_file(src_path: &PathBuf, name: Option<&str>) -> Result<usize> {
    let content = std::fs::read_to_string(src_path)
        .with_context(|| format!("Failed to read {}", src_path.display()))?;

    let cookies_dir = app_data_dir()
        .ok_or_else(|| anyhow::anyhow!("Cannot determine app data directory"))?
        .join(COOKIES_DIR);

    std::fs::create_dir_all(&cookies_dir)?;

    let dest_file = if let Some(n) = name {
        cookies_dir.join(format!("cookies_{}.txt", n))
    } else {
        cookies_dir.join(DEFAULT_COOKIE_FILE)
    };

    // Parse to validate and count
    let parsed = parse_netscape_cookies(&content);
    if parsed.is_empty() {
        anyhow::bail!("No valid cookies found in file (expected Netscape format)");
    }

    // Copy the raw file (preserving original format for yt-dlp consumption)
    // Normalize line endings but otherwise keep as-is

View on GitHub (pinned to 8600b91f42)