tonhowtf/omniget · critical

Could not determine data directory

Error message

Could not determine data directory

What it means

download_model calls models_dir(), which returns Option<PathBuf>; when it yields None (the app data directory cannot be determined) the model download aborts with 'Could not determine data directory'. This typically means the OS-specific base-directory lookup failed.

Solutions

  1. Ensure HOME (Linux/macOS) or USERPROFILE (Windows) is set for the process running the app.
  2. Set XDG_DATA_HOME (Linux) or an equivalent env var so the data directory can be resolved.
  3. Allow overriding the models directory via configuration so users can pass an explicit path.
  4. Inspect models_dir()'s implementation to see which directory API returns None on your platform.

Example fix

// before (shell)
cargo tauri dev   # fails under service: no HOME
// after (shell)
export HOME=/home/appuser
export XDG_DATA_HOME=/var/lib/appuser/.local/share
cargo tauri dev
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-check before starting downloads
if std::env::var("HOME").is_err() && std::env::var("XDG_DATA_HOME").is_err() {
    return Err("set HOME or XDG_DATA_HOME so the models directory can be resolved".into());
}

Try / catch

match download_model(id, progress).await {
    Err(e) if e.to_string().contains("Could not determine data directory") => {
        // fall back: set a temp dir override or prompt the user for a models folder
        eprintln!("data directory unresolved; configure an explicit models directory");
    }
    other => other?,
}

Prevention

When it happens

Trigger: models_dir() returns None because the required XDG/HOME environment variables are unset (headless Linux/service contexts) or the platform's data-dir API fails during a model download.

Common situations: Running the app as a systemd service or cron job with no HOME set, containerized environments without XDG_DATA_HOME, or unusual Windows profile configurations.

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

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/whisper.rs:89

                    .replace("q5_0", "(q5)")
                    .replace("q5_1", "(q5)"),
                size_mb: *mb,
                note: note.to_string(),
                installed: size > 0,
                path: path
                    .filter(|_| size > 0)
                    .map(|p| p.to_string_lossy().to_string()),
                size_bytes: size,
            }
        })
        .collect()
}

pub async fn download_model(id: &str, progress: ProgressFn) -> anyhow::Result<PathBuf> {
    if !MODELS.iter().any(|(m, _, _)| *m == id) {
        return Err(anyhow!("modelo desconhecido: {}", id));
    }
    let dir = models_dir().ok_or_else(|| anyhow!("Could not determine data directory"))?;
    std::fs::create_dir_all(&dir)?;
    let dest = dir.join(format!("ggml-{}.bin", id));
    let url = format!("{}/ggml-{}.bin", HF_BASE, id);
    let client = super::client()?;
    super::download_to(
        &client,
        &url,
        &dest,
        &progress,
        &format!("whisper-model:{}", id),
    )
    .await?;
    Ok(dest)
}

pub fn remove_model(id: &str) -> anyhow::Result<()> {
    let dir = models_dir().ok_or_else(|| anyhow!("Could not determine data directory"))?;
    let p = dir.join(format!("ggml-{}.bin", id));

View on GitHub (pinned to 8600b91f42)