{"record":{"id":"a3a205501c5e299e","repo":"tonhowtf/omniget","slug":"could-not-determine-app-data-dir","errorCode":null,"errorMessage":"could not determine app data dir","messagePattern":"could not determine app data dir","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/pdfium.rs","lineNumber":163,"sourceCode":"\npub fn read_version_marker() -> Option<String> {\n    let p = pdfium_version_marker_path()?;\n    let s = std::fs::read_to_string(&p).ok()?;\n    let trimmed = s.trim().to_string();\n    if trimmed.is_empty() {\n        None\n    } else {\n        Some(trimmed)\n    }\n}\n\npub async fn ensure_pdfium() -> anyhow::Result<PathBuf> {\n    ensure_pdfium_with_variant(None).await\n}\n\npub async fn ensure_pdfium_with_variant(variant: Option<String>) -> anyhow::Result<PathBuf> {\n    let target_dir =\n        pdfium_target_dir().ok_or_else(|| anyhow!(\"could not determine app data dir\"))?;\n    std::fs::create_dir_all(&target_dir)\n        .with_context(|| format!(\"creating pdfium target dir {}\", target_dir.display()))?;\n\n    let archive_name = archive_name_for_variant(variant.as_deref());\n    let url = format!(\"{}/{}\", PDFIUM_DOWNLOAD_BASE, archive_name);\n    let lib_filename = pdfium_lib_filename();\n    let target_path = target_dir.join(lib_filename);\n\n    tracing::info!(\"Downloading pdfium from {}\", url);\n\n    let client = crate::core::http_client::apply_global_proxy(reqwest::Client::builder())\n        .timeout(std::time::Duration::from_secs(600))\n        .build()?;\n\n    let response = client.get(&url).send().await?;\n    if !response.status().is_success() {\n        return Err(anyhow!(\n            \"Failed to download pdfium from {}: HTTP {}\",","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/pdfium.rs#L145-L181","documentation":"ensure_pdfium_with_variant() resolves the directory where the pdfium native library will be installed via pdfium_target_dir(). If that resolver returns None (app data dir unavailable, e.g. called outside the Tauri context or the platform provides no data dir), installation cannot proceed and this error is thrown before any download happens.","triggerScenarios":"Calling ensure_pdfium() or ensure_pdfium_with_variant() when pdfium_target_dir() returns None — typically before Tauri app setup completes, in tests, or on systems where the OS data-dir lookup fails.","commonSituations":"First-run pdfium download on a machine with a misconfigured XDG_DATA_HOME/HOME; invoking installer logic from a headless test; running on an unsupported platform where the data dir API returns None.","solutions":["Call ensure_pdfium after the app data directory is initialized and resolvable","Verify platform data-dir environment (HOME, XDG_DATA_HOME, APPDATA) is set","Inspect pdfium_target_dir() and add a fallback path or clearer diagnostic","For headless/CI use, pre-install pdfium manually via set_pdfium_from_path"],"exampleFix":"// before\nlet target_dir = pdfium_target_dir().ok_or_else(|| anyhow!(\"could not determine app data dir\"))?;\n// after\nlet target_dir = pdfium_target_dir()\n    .or_else(|| dirs::data_dir().map(|d| d.join(\"pdfium\")))\n    .ok_or_else(|| anyhow!(\"could not determine app data dir\"))?;","handlingStrategy":"validation","validationCode":"fn pdfium_installable() -> bool {\n    std::env::var(\"HOME\").is_ok()\n        || std::env::var(\"APPDATA\").is_ok()\n        || std::env::var(\"XDG_DATA_HOME\").is_ok()\n}","typeGuard":null,"tryCatchPattern":"match ensure_pdfium().await {\n    Err(e) if e.to_string().contains(\"app data dir\") => {\n        // fall back to a system-wide or bundled pdfium\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Initialize the Tauri data directory before any ensure_pdfium call in startup order","Set HOME/APPDATA/XDG_DATA_HOME explicitly in headless and CI environments","Add a fallback path in pdfium_target_dir() for non-Tauri usage"],"tags":["rust","filesystem","pdfium"],"backgroundTag":"missing-config-value","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"}