{"record":{"id":"3b73cc909da08ad9","repo":"xpzouying/xiaohongshu-mcp","slug":"hdiutil-attach-v-s","errorCode":null,"errorMessage":"hdiutil attach: %v: %s","messagePattern":"hdiutil attach: (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browser/browser_download.go","lineNumber":310,"sourceCode":"\t\t_, err = io.Copy(out, rc)\n\t\tout.Close()\n\t\trc.Close()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc extractDmg(archivePath, destDir string) error {\n\tmountPoint, err := os.MkdirTemp(\"\", \"bx-dmg-\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer os.RemoveAll(mountPoint)\n\n\tif out, err := exec.Command(\"hdiutil\", \"attach\", archivePath, \"-nobrowse\", \"-mountpoint\", mountPoint).CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"hdiutil attach: %v: %s\", err, out)\n\t}\n\tdefer exec.Command(\"hdiutil\", \"detach\", mountPoint, \"-quiet\").Run()\n\n\tvar appPath string\n\tentries, _ := os.ReadDir(mountPoint)\n\tfor _, e := range entries {\n\t\tif strings.HasSuffix(e.Name(), \".app\") {\n\t\t\tappPath = filepath.Join(mountPoint, e.Name())\n\t\t\tbreak\n\t\t}\n\t}\n\tif appPath == \"\" {\n\t\treturn fmt.Errorf(\"dmg 内未找到 .app\")\n\t}\n\tdstApp := filepath.Join(destDir, filepath.Base(appPath))\n\tif out, err := exec.Command(\"cp\", \"-R\", appPath, dstApp).CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"拷贝 .app: %v: %s\", err, out)\n\t}","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/browser/browser_download.go#L292-L328","documentation":"On macOS, extractDmg mounts the downloaded .dmg via the external `hdiutil attach` command with -nobrowse and a temporary mountpoint. This error wraps both the exec error and the combined stdout/stderr output when hdiutil fails to mount the image.","triggerScenarios":"extractArchive -> extractDmg on macOS runs exec.Command(\"hdiutil\", \"attach\", archivePath, ...).CombinedOutput() and the command returns a non-zero exit code (corrupt image, no disk image, permissions, security agent blocking).","commonSituations":"The .dmg download was truncated or corrupted (hdiutil reports 'no mountable file systems'); macOS security policies or MDM block hdiutil; the binary was quarantined and Gatekeeper interferes; running in a CI macOS runner without GUI/permission; disk space exhaustion.","solutions":["Re-download the .dmg (clear cache, re-run EnsureBrowser) — the most common cause is a corrupt/truncated image","Verify the archive passes SHA256 verification (verifySHA256 should have caught corruption, but confirm the cache file wasn't damaged afterwards)","Run hdiutil attach <file> -nobrowse manually to see the full error output","Check free disk space and that /tmp (or the mountpoint parent) is writable","On CI, ensure the runner permits mounting disk images or switch to a zip-based distribution"],"exampleFix":"// before\nif out, err := exec.Command(\"hdiutil\", \"attach\", archivePath, \"-nobrowse\", \"-mountpoint\", mountPoint).CombinedOutput(); err != nil {\n\treturn fmt.Errorf(\"hdiutil attach: %v: %s\", err, out)\n}\n// after — verify the image first for a clearer message\nif out, err := exec.Command(\"hdiutil\", \"imageinfo\", archivePath).CombinedOutput(); err != nil {\n\treturn fmt.Errorf(\"损坏的 dmg (imageinfo 失败): %v: %s\", err, out)\n}\nif out, err := exec.Command(\"hdiutil\", \"attach\", archivePath, \"-nobrowse\", \"-mountpoint\", mountPoint).CombinedOutput(); err != nil {\n\treturn fmt.Errorf(\"hdiutil attach: %v: %s\", err, out)\n}","handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"hdiutil\", \"imageinfo\", dmgPath).CombinedOutput()\nif err != nil {\n\t// dmg 已损坏，先重新下载\n}","typeGuard":null,"tryCatchPattern":"if err := EnsureBrowser(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"hdiutil attach\") {\n\t\t// dmg 损坏或被安全策略拦截：清缓存重下，或改用 zip 分发\n\t\tos.RemoveAll(cacheDir)\n\t\treturn EnsureBrowser(ctx)\n\t}\n\treturn err\n}","preventionTips":["Verify the .dmg SHA256 before mounting (already done by verifySHA256)","Ensure enough free disk space before install","On CI macOS runners, confirm hdiutil/mounting is permitted","Keep the quarantine xattr removal step to avoid Gatekeeper issues"],"tags":["macos","dmg","hdiutil","mount","external-command"],"backgroundTag":"dmg-mount-failed","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}