{"record":{"id":"620e5534c0ef0244","repo":"run-llama/liteparse","slug":"userprofile-env-var-not-set","errorCode":null,"errorMessage":"USERPROFILE env var not set","messagePattern":"USERPROFILE env var not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pdfium-sys/build.rs","lineNumber":134,"sourceCode":"    let base = dirs_cache().join(\"pdfium-rs\");\n    let tag_safe = PDFIUM_RELEASE_TAG.replace('/', \"_\");\n    let asset = pdfium_asset_stem();\n    base.join(tag_safe).join(asset)\n}\n\nfn dirs_cache() -> PathBuf {\n    if let Ok(xdg) = env::var(\"XDG_CACHE_HOME\") {\n        return PathBuf::from(xdg);\n    }\n\n    let target_os = env::var(\"CARGO_CFG_TARGET_OS\").unwrap_or_default();\n\n    // Windows -> USERPROFILE\n    if target_os == \"windows\" {\n        if let Ok(local_app_data) = env::var(\"LOCALAPPDATA\") {\n            return PathBuf::from(local_app_data);\n        }\n        let home = env::var(\"USERPROFILE\").expect(\"USERPROFILE env var not set\");\n        return PathBuf::from(home).join(\"AppData\\\\Local\");\n    }\n\n    let home = env::var(\"HOME\").expect(\"HOME env var not set\");\n    if target_os == \"macos\" {\n        PathBuf::from(&home).join(\"Library/Caches\")\n    } else {\n        PathBuf::from(&home).join(\".cache\")\n    }\n}\n\n/// Map target triple to the pdfium-binaries asset name (without .tgz).\nfn pdfium_asset_stem() -> &'static str {\n    let target = env::var(\"TARGET\").unwrap();\n    match target.as_str() {\n        \"aarch64-apple-darwin\" => \"pdfium-mac-arm64\",\n        \"x86_64-apple-darwin\" => \"pdfium-mac-x64\",\n        // Universal macOS binary works for both, but we prefer arch-specific","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/pdfium-sys/build.rs#L116-L152","documentation":"In pdfium-sys's build script, dirs_cache determines the cache directory per-platform. On Windows it prefers LOCALAPPDATA but falls back to USERPROFILE; if neither environment variable is set, the .expect on USERPROFILE panics with this message. The build script cannot locate a per-user cache directory for the downloaded pdfium library.","triggerScenarios":"Running `cargo build` of a workspace depending on pdfium-sys on Windows inside an environment where both LOCALAPPDATA and USERPROFILE are unset — e.g. a stripped-down CI container, a service account with a minimal environment, or a custom build runner.","commonSituations":"Windows CI runners (Docker executors, GitHub Actions containers) that don't provision standard user env vars; build tools that sanitize the environment; running cargo under a Windows service account with no user profile.","solutions":["Set USERPROFILE (e.g. USERPROFILE=C:\\Users\\builduser) in the build environment.","Set LOCALAPPDATA instead — it is checked first and short-circuits the USERPROFILE lookup.","Pre-populate the pdfium cache directory so the download path (and dirs_cache) is avoided, e.g. via the crate's cache-dir override if available.","In CI, use a runner image that initializes the standard Windows user environment."],"exampleFix":"// before: stripped CI step\n- run: cargo build\n\n// after: ensure env vars exist\n- run: |\n    echo \"USERPROFILE=$USERPROFILE\"\n    cargo build\n  env:\n    USERPROFILE: C:\\Users\\runneradmin\n    LOCALAPPDATA: C:\\Users\\runneradmin\\AppData\\Local","handlingStrategy":"validation","validationCode":"// CI preflight (PowerShell): fail fast if env is missing\nif (-not $env:LOCALAPPDATA -and -not $env:USERPROFILE) {\n  throw \"Set USERPROFILE or LOCALAPPDATA before building\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set USERPROFILE/LOCALAPPDATA explicitly in Windows CI containers","Add an env sanity check as the first CI step","Avoid sanitizing the environment when invoking cargo"],"tags":["build-script","windows","environment","pdfium"],"backgroundTag":"missing-env-var","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}