{"record":{"id":"3f6b90ad1511a0f3","repo":"hashicorp/packer","slug":"failed-to-open-packer-release-zip-s","errorCode":null,"errorMessage":"failed to open Packer release zip: %s","messagePattern":"failed to open Packer release zip: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":503,"sourceCode":"\tisWindows := strings.Contains(strings.ToLower(osType), \"windows\")\n\n\tvar remotePath, binaryName string\n\tif isWindows {\n\t\tbinaryName = \"packer.exe\"\n\t\tremotePath = \"C:\\\\Windows\\\\Temp\\\\packer-sbom-runner.exe\"\n\t} else {\n\t\tbinaryName = \"packer\"\n\t\tremotePath = \"/tmp/packer-sbom-runner\"\n\t}\n\n\tif isWindows {\n\t\tremoteDir := \"C:\\\\Windows\\\\Temp\"\n\t\tremoteZipPath := remoteDir + \"\\\\packer-sbom-runner.zip\"\n\n\t\t// Step 1: upload zip to remote.\n\t\tzipFile, err := os.Open(localZipPath)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to open Packer release zip: %s\", err)\n\t\t}\n\t\tdefer func() { _ = zipFile.Close() }()\n\n\t\tlog.Printf(\"[INFO] Uploading Packer release zip to %s...\", remoteZipPath)\n\t\tif err := comm.Upload(remoteZipPath, zipFile, nil); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to upload Packer release zip: %s\", err)\n\t\t}\n\n\t\t// Single PowerShell command: extract, move binary, remove zip.\n\t\tpsCmd := fmt.Sprintf(\n\t\t\t`powershell -NoProfile -ExecutionPolicy Bypass -Command `+\n\t\t\t\t`\"$ErrorActionPreference='Stop'; `+\n\t\t\t\t`Expand-Archive -Path '%s' -DestinationPath '%s' -Force; `+\n\t\t\t\t`if (!(Test-Path '%s\\%s')) { throw 'packer.exe not found after extraction' }; `+\n\t\t\t\t`Move-Item -Force '%s\\%s' '%s'; `+\n\t\t\t\t`Remove-Item -Force '%s'\"`,\n\t\t\tremoteZipPath, remoteDir,\n\t\t\tremoteDir, binaryName,","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L485-L521","documentation":"This error wraps an os.Open failure when uploadScanner tries to open the locally cached Packer release zip before uploading it to a Windows guest. It is thrown by the hcp-sbom provisioner's Windows path in provisioner/hcp-sbom/provisioner.go:503; the wrapped OS error is embedded verbatim, so the actual cause (ENOENT, EACCES, etc.) appears in the message text. It means the provisioner could not even read the local zip file, before any network/upload work started.","triggerScenarios":"os.Open(localZipPath) fails inside uploadScanner (Windows guest path) — i.e. the local zip path does not exist, is a directory, or the Packer process lacks read permission. Called by provisionWithNativeGeneration during a build using the hcp-sbom provisioner with a Windows target OS.","commonSituations":"The configured release zip path points to a file that was never downloaded or was deleted by a prior build step; a typo or wrong variable interpolation in the zip path config; the Packer process runs as a user without read access to the zip; a race where a cleanup step removed the zip before the provisioner ran.","solutions":["Verify the local zip path exists and is readable: run `ls -l <localZipPath>` (or equivalent) as the same user running Packer.","Fix the config/variable that produces localZipPath — check the hcp-sbom provisioner config and interpolated path for typos.","Ensure an earlier download step actually produced the zip before the provisioner runs (check build ordering).","Grant the Packer process read permission on the file, or move the zip somewhere the Packer user can read.","Re-run with PACKER_LOG=1 to see the wrapped OS error detail (no such file vs permission denied)."],"exampleFix":"// before (path from a misconfigured variable)\nos.Open(cfg.ReleaseZipPath) // -> \"failed to open Packer release zip: open /opt/packer.zip: no such file or directory\"\n// after (validate/derive the real path before the build)\nif _, err := os.Stat(releaseZipPath); err != nil {\n\tlog.Fatalf(\"release zip missing at %s: %v\", releaseZipPath, err)\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(localZipPath)\nif err != nil {\n\treturn fmt.Errorf(\"release zip unavailable before build: %w\", err)\n}\nif err != nil || info.IsDir() {\n\treturn fmt.Errorf(\"%s is not a readable file\", localZipPath)\n}\nf, err := os.Open(localZipPath)\nif err != nil {\n\treturn fmt.Errorf(\"cannot read release zip %s: %w\", localZipPath, err)\n}\n_ = f.Close()","typeGuard":null,"tryCatchPattern":"_, err := os.Open(localZipPath)\nif err != nil {\n\tif errors.Is(err, os.ErrNotExist) {\n\t\t// redownload or fix path\n\t} else if errors.Is(err, os.ErrPermission) {\n\t\t// fix file permissions\n\t}\n\treturn err\n}","preventionTips":["os.Stat the zip path in a pre-build validation step and fail fast with a clear message.","Pin and log the zip path resolved from config so typos surface early.","Keep download and provision steps in the same build lifecycle so the zip cannot be garbage-collected between them.","Run Packer as a user with read access to the artifact cache directory.","Verify zip checksums after download to catch truncated files."],"tags":["file-io","windows","provisioner","hcp-sbom"],"backgroundTag":"file-not-found","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}