tonhowtf/omniget · error

external_data_cache: app data dir unavailable

Error message

external_data_cache: app data dir unavailable

What it means

external_data_cache resolves the base directory for a plugin's external cache. In portable mode (OMNIGET_PORTABLE env var set) it uses omniget_core::core::paths::app_data_dir(); when that returns None it raises this error. It means the portable install's app data directory could not be determined, so no cache directory can be created.

Solutions

  1. Check that OMNIGET_PORTABLE is intentionally set; unset it to use the normal OS cache dir path.
  2. Ensure the executable lives in a writable, resolvable location so app_data_dir() can compute the dir.
  3. Pass a fallback base dir explicitly to the cache helper.
  4. If persistent, file a bug with paths::app_data_dir including OS and launch context.

Example fix

// before
let base = paths::app_data_dir().ok_or_else(|| anyhow!("external_data_cache: app data dir unavailable"))?.join("cache");
// after (caller fallback)
match plugin_host.external_data_cache(plugin_id, ns) {
    Ok(dir) => dir,
    Err(e) => { log::warn!("cache unavailable: {e}"); std::env::temp_dir().join("omniget-cache") }
}
Defensive patterns

Strategy: fallback

Validate before calling

let portable = std::env::var("OMNIGET_PORTABLE").is_ok();
if portable && omniget_core::core::paths::app_data_dir().is_none() {
    eprintln!("portable mode cannot resolve app data dir; unset OMNIGET_PORTABLE or run from a writable location");
}

Try / catch

let dir = match host.external_data_cache(pid, ns) {
    Ok(d) => d,
    Err(e) => { log::warn!("cache fallback: {e}"); std::env::temp_dir().join("omniget-external-cache") }
};

Prevention

When it happens

Trigger: Calling external_data_cache with OMNIGET_PORTABLE set while paths::app_data_dir() returns None — typically when the executable path cannot be resolved or the computed app dir fails platform constraints (e.g. running from a weird location, permission on the exe path).

Common situations: Portable build run from a read-only mount or temp dir where the exe path resolution fails; exotic launch context (systemd service, container) without the expected env; regression in the paths helper on a platform update.

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/441904742336846b. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/plugin_host.rs:131

    fn external_data_cache(&self, plugin_id: &str, namespace: &str) -> anyhow::Result<PathBuf> {
        if plugin_id.is_empty() {
            anyhow::bail!("external_data_cache: plugin_id must not be empty");
        }
        if namespace.is_empty() {
            anyhow::bail!("external_data_cache: namespace must not be empty");
        }
        if plugin_id.contains(['/', '\\', ':', '\0']) || namespace.contains(['/', '\\', ':', '\0'])
        {
            anyhow::bail!(
                "external_data_cache: plugin_id/namespace must not contain path separators or null bytes"
            );
        }

        // portable installs keep every file next to the app, so the cache
        // lives under the app data dir instead of the OS cache dir
        let base = if std::env::var("OMNIGET_PORTABLE").is_ok() {
            omniget_core::core::paths::app_data_dir()
                .ok_or_else(|| anyhow::anyhow!("external_data_cache: app data dir unavailable"))?
                .join("cache")
        } else {
            dirs::cache_dir()
                .ok_or_else(|| {
                    anyhow::anyhow!(
                        "external_data_cache: OS cache dir unavailable on this platform"
                    )
                })?
                .join("wtf.tonho.omniget")
        };
        let dir = base.join("external-cache").join(plugin_id).join(namespace);
        std::fs::create_dir_all(&dir).map_err(|e| {
            anyhow::anyhow!(
                "external_data_cache: failed to create {}: {}",
                dir.display(),
                e
            )
        })?;

View on GitHub (pinned to 8600b91f42)