{"record":{"id":"33643dd08b5c7496","repo":"hashicorp/packer","slug":"failed-to-compute-destination-path-q-s","errorCode":null,"errorMessage":"failed to compute destination path %q: %s","messagePattern":"failed to compute destination path %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":912,"sourceCode":"\t}\n\tdefer func() {\n\t\t_ = outFile.Close() // Cleanup, ignore error\n\t}()\n\n\terr = json.NewEncoder(outFile).Encode(PackerSBOM{\n\t\tRawSBOM: sbomData,\n\t\tFormat:  format,\n\t\tName:    p.config.SbomName,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write SBOM to %q: %s\", pkrDst, err)\n\t}\n\n\t// Also save to user destination if specified\n\tif p.config.Destination != \"\" {\n\t\tusrDst, err := p.getUserDestination()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compute destination path %q: %s\", p.config.Destination, err)\n\t\t}\n\t\tif err := os.WriteFile(usrDst, sbomData, 0644); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write SBOM to destination %q: %s\", usrDst, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Communicator returns the communicator for elevated execution\nfunc (p *Provisioner) Communicator() packersdk.Communicator {\n\treturn p.communicator\n}\n\n// ElevatedUser returns the elevated user for Windows execution\nfunc (p *Provisioner) ElevatedUser() string {\n\treturn p.config.ElevatedUser\n}","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L894-L930","documentation":"This error is returned when the optional user-facing destination (p.config.Destination) is set, but p.getUserDestination() fails to compute the concrete user file path from it. The configured Destination template/path is invalid for the path-expansion logic (e.g. bad template variables or unusable path expression), so the raw SBOM was never written for the user.","triggerScenarios":"config.Destination is non-empty and getUserDestination() returns an error while expanding/validating the configured destination path — for example an unknown template variable, malformed path, or the expansion function returning an error for the given string.","commonSituations":"Users set destination with unsupported template syntax (misspelled variables like {{ .Foo }}), an absolute path with invalid characters on Windows, or a path referencing data not available at provision time.","solutions":["Read the wrapped error to see which part of the path expansion failed.","Simplify the destination to a plain writable path (e.g. ./sbom.json or /tmp/sbom.json) and rebuild.","If using Packer template variables in destination, use only supported ones (e.g. build-specific variables) with correct syntax {{ .VarName }}.","Verify path separators are valid for the OS where Packer runs.","Clear or unset destination if you only need the HCP-internal copy."],"exampleFix":"// before (HCL)\ndestination = \"/out/{{ .Bogus }}/sbom.json\"\n// after\ndestination = \"/out/{{ build `ID` }}/sbom.json\"  // or a static path: \"/out/sbom.json\"","handlingStrategy":"validation","validationCode":"if cfg.Destination != \"\" {\n\textended, err := interpolate.Render(cfg.Destination, ctxData)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid destination %q: %w\", cfg.Destination, err)\n\t}\n\tif filepath.Clean(extended) == \"\" || strings.HasSuffix(extended, string(os.PathSeparator)) {\n\t\treturn fmt.Errorf(\"destination %q must be a file path\", cfg.Destination)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only supported template variables in destination and double-check {{ }} syntax.","Use OS-appropriate path separators for the machine running Packer.","Smoke-test a new destination value with a trivial build first.","Leave destination unset if you only need the HCP-managed copy."],"tags":["go","path","template","configuration"],"backgroundTag":"invalid-destination-path","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"}