{"record":{"id":"d29dab9948a5007d","repo":"hashicorp/packer","slug":"failed-to-process-sbom-s","errorCode":null,"errorMessage":"failed to process SBOM: %s","messagePattern":"failed to process SBOM: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":665,"sourceCode":"\t// Step 3: Run scanner on remote\n\tui.Say(fmt.Sprintf(\"Running scanner on remote host (scanning %s)...\", p.config.ScanPath))\n\tremoteSBOMPath, err := p.runScanner(ctx, ui, comm, remoteScannerPath, osType)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to run scanner: %s\", err)\n\t}\n\tdefer p.cleanupRemoteFile(ctx, ui, comm, remoteSBOMPath)\n\n\t// Step 4: Download SBOM from remote\n\tlog.Println(\"Downloading SBOM from remote host...\")\n\tsbomData, err := p.downloadSBOM(ctx, ui, comm, remoteSBOMPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to download SBOM: %s\", err)\n\t}\n\n\t// Step 5: Process SBOM for HCP (validate, compress, store)\n\tlog.Println(\"Processing SBOM for HCP Packer...\")\n\tif err := p.processSBOMForHCP(generatedData, sbomData); err != nil {\n\t\treturn fmt.Errorf(\"failed to process SBOM: %s\", err)\n\t}\n\n\tui.Say(\"Automatic SBOM generation completed successfully\")\n\treturn nil\n}\n\n// runScanner executes `packer sbom-generate` on the remote host.\nfunc (p *Provisioner) runScanner(ctx context.Context, ui packersdk.Ui,\n\tcomm packersdk.Communicator, scannerPath, osType string) (string, error) {\n\n\t// Determine output path based on OS\n\tvar outputPath string\n\tisWindows := strings.Contains(strings.ToLower(osType), \"windows\")\n\tif isWindows {\n\t\toutputPath = \"C:\\\\Windows\\\\Temp\\\\packer-sbom.json\"\n\t} else {\n\t\toutputPath = \"/tmp/packer-sbom.json\"\n\t}","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L647-L683","documentation":"This wrapper error is returned by provisionWithNativeGeneration (provisioner/hcp-sbom/provisioner.go:665) when p.processSBOMForHCP fails after a successful download. processSBOMForHCP validates the SBOM format, extracts the Packer destination path from generatedData, and writes the artifact for HCP upload. Any failure inside those steps is wrapped with this message, so inspect the nested text for the real cause.","triggerScenarios":"Calling `packer build` in native-generation mode when processSBOMForHCP returns an error: validateSBOM rejects the downloaded bytes (not valid SPDX/CycloneDX JSON), generatedData lacks a \"dst\" key (internal bug), or os.Create on the local destination path fails (permissions, nonexistent directory).","commonSituations":"The scanner produced an error page or empty/partial file instead of a valid SBOM; the scanner wrote a text/plain log instead of JSON; the local Packer output directory is read-only or was removed mid-build; running Packer with a version that has an internal data-plumbing bug.","solutions":["Read the wrapped cause: 'SBOM validation failed' means the scanner output is malformed; 'packer destination path missing' is an internal error worth reporting; 'failed to create output file' means check local fs permissions.","Inspect /tmp/packer-sbom.json on the remote (before cleanup) or capture scanner stdout in the log to see what was actually generated.","Verify scanner_args produce JSON output (e.g. correct format flag for syft/trivy wrapper) and that the scan path exists on the guest.","Ensure the local directory Packer writes PackerSBOM artifacts into is writable and exists.","If 'internal error' is shown, upgrade Packer to the latest patch release and file an issue if it persists."],"exampleFix":"// before: scanner args emit text format\nscanner_args = [\"--format\", \"table\"]\n// after: request a machine-readable SBOM format\nscanner_args = [\"--format\", \"cyclonedx-json\"]","handlingStrategy":"validation","validationCode":"// Pre-validate scanner args request a machine-readable format\nallowed := []string{\"--format\", \"cyclonedx-json\", \"--format\", \"spdx-json\"}\n// ensure scanner_args select a JSON SBOM format, not table/text","typeGuard":null,"tryCatchPattern":"if err := p.processSBOMForHCP(generatedData, sbomData); err != nil {\n    return fmt.Errorf(\"failed to process SBOM: %w\", err) // branch on wrapped cause\n}","preventionTips":["Pin scanner_args to a JSON SBOM format.","Keep the local Packer output directory writable.","Capture scanner stdout in logs to debug malformed output.","Stay on a supported Packer release to avoid internal plumbing bugs."],"tags":["packer","sbom","provisioner","validation"],"backgroundTag":"sbom-processing-failed","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"}