{"record":{"id":"f55f58e48a846b6e","repo":"jdx/mise","slug":"brew-cask-pkgutil-receipt-check-for-pkg-id-is-f55f58","errorCode":null,"errorMessage":"brew-cask: pkgutil receipt check for '{pkg_id}' is only available on macOS","messagePattern":"brew-cask: pkgutil receipt check for '(.+?)' is only available on macOS","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/state.rs","lineNumber":131,"sourceCode":"}\n\npub(super) fn homebrew_metadata_present(token: &str) -> Result<bool> {\n    let path = caskroom_token_dir(token).join(\".metadata\");\n    match path.symlink_metadata() {\n        Ok(_) => Ok(true),\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(false),\n        Err(err) => Err(err).wrap_err_with(|| {\n            format!(\n                \"brew-cask:{token}: failed to inspect Homebrew metadata at '{}'\",\n                path.display()\n            )\n        }),\n    }\n}\n\npub(super) fn pkg_id_installed(pkg_id: &str) -> Result<bool> {\n    #[cfg(not(target_os = \"macos\"))]\n    bail!(\"brew-cask: pkgutil receipt check for '{pkg_id}' is only available on macOS\");\n\n    #[cfg(target_os = \"macos\")]\n    // Homebrew's pkgutil metadata is a regular expression, not a literal ID.\n    // Match it with pkgutil itself to preserve its nonstandard regexp semantics.\n    // Like Homebrew, use the returned IDs rather than the exit status because a\n    // query with no matches may exit unsuccessfully.\n    let output = std::process::Command::new(\"pkgutil\")\n        .arg(format!(\"--pkgs={pkg_id}\"))\n        .stdin(std::process::Stdio::null())\n        .stderr(std::process::Stdio::null())\n        .output()?;\n    #[cfg(target_os = \"macos\")]\n    Ok(pkgutil_output_has_match(&output.stdout))\n}\n\n#[cfg(any(target_os = \"macos\", test))]\npub(super) fn pkgutil_output_has_match(output: &[u8]) -> bool {\n    output.iter().any(|byte| !byte.is_ascii_whitespace())","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/cask/state.rs#L113-L149","documentation":"pkg_id_installed checks macOS's pkgutil receipt database to see whether a cask's .pkg installer receipt exists. Homebrew only records pkg receipts on macOS, so calling this on any other platform is a programming error and mise bails immediately instead of returning a misleading result.","triggerScenarios":"pkg_id_installed is invoked on a non-macOS target (the #[cfg(not(target_os = \"macos\"))] arm), reached via pkg_ids_installed during cask state/receipt evaluation.","commonSituations":"Running mise cask management code paths on Linux/Windows CI; cross-platform code that unconditionally queries pkg receipts for a brew cask.","solutions":["Only call pkg_ids_installed/pkg_id_installed on macOS (guard with cfg(target_os = \"macos\") or an OS check at the call site)","Skip pkg-receipt validation for casks on non-macOS platforms","If you need equivalent checks elsewhere, use the platform's own package receipt mechanism instead"],"exampleFix":"// before\nlet installed = pkg_ids_installed(&receipt.pkg_ids)?;\n// after\n#[cfg(target_os = \"macos\")]\nlet installed = pkg_ids_installed(&receipt.pkg_ids)?;\n#[cfg(not(target_os = \"macos\"))]\nlet installed = false;","handlingStrategy":"validation","validationCode":"#[cfg(target_os = \"macos\")]\nlet installed = pkg_ids_installed(&receipt.pkg_ids)?;\n#[cfg(not(target_os = \"macos\"))]\nlet installed = false;","typeGuard":"const fn pkg_receipts_supported() -> bool { cfg!(target_os = \"macos\") }","tryCatchPattern":null,"preventionTips":["Gate pkg-receipt checks behind cfg(target_os = \"macos\")","Treat pkg_ids as macOS-only metadata in shared receipt structs","Test cask flows on all target platforms in CI"],"tags":["platform","macos","pkgutil","unsupported-operation"],"backgroundTag":"unsupported-platform","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}