{"record":{"id":"2ed4a4ad50462a9d","repo":"hashicorp/packer","slug":"failed-to-get-current-working-directory-for-packer","errorCode":null,"errorMessage":"failed to get current working directory for Packer SBOM: %s","messagePattern":"failed to get current working directory for Packer SBOM: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/provisioner.go","lineNumber":358,"sourceCode":"\t// Try to delegate to inner provisioner if it implements FlatConfig\n\tif fc, ok := p.Provisioner.(interface{ FlatConfig() interface{} }); ok {\n\t\treturn fc.FlatConfig()\n\t}\n\treturn nil\n}\n\nfunc (p *SBOMInternalProvisioner) Prepare(raws ...interface{}) error {\n\treturn p.Provisioner.Prepare(raws...)\n}\n\nfunc (p *SBOMInternalProvisioner) Provision(\n\tctx context.Context, ui packersdk.Ui, comm packersdk.Communicator,\n\tgeneratedData map[string]interface{},\n) error {\n\t// Original implementation - all logic now in hcp-sbom provisioner\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current working directory for Packer SBOM: %s\", err)\n\t}\n\n\ttmpFile, err := os.CreateTemp(cwd, \"packer-sbom-*.json\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create internal temporary file for Packer SBOM: %s\", err)\n\t}\n\n\ttmpFileName := tmpFile.Name()\n\tif err = tmpFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"failed to close temporary file for Packer SBOM %s: %s\", tmpFileName, err)\n\t}\n\n\tdefer func(name string) {\n\t\tfileRemoveErr := os.Remove(name)\n\t\tif fileRemoveErr != nil {\n\t\t\tlog.Printf(\"Error removing SBOM temporary file %s: %s\", name, fileRemoveErr)\n\t\t}\n\t}(tmpFile.Name())","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/provisioner.go#L340-L376","documentation":"The internal SBOM provisioner delegates to the hcp-sbom provisioner and first needs a temp file created in the current working directory. If os.Getwd() fails (e.g. the working directory was deleted or is unreadable), Provision returns this wrapped error.","triggerScenarios":"Calling Provision on the built-in SBOM provisioner (packer/provisioner.go:Provision) when os.Getwd() returns an error — typically because the process's current working directory no longer exists or lacks permissions.","commonSituations":"Running Packer from a directory deleted/recreated by a prior build step; running in a container whose WORKDIR was removed; a CI job that cd's into a temp dir which is cleaned mid-run.","solutions":["Re-run Packer from an existing, writable directory.","Fix the preceding pipeline step that removed or recreated the working directory.","Ensure the container/CI job's working directory exists and is readable before invoking packer."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := os.Getwd(); err != nil {\n  return fmt.Errorf(\"cannot run SBOM provisioner: working directory unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := p.Provision(ctx, ui, comm, data); err != nil {\n  if strings.Contains(err.Error(), \"current working directory for Packer SBOM\") {\n    // restart packer from an existing directory\n  }\n}","preventionTips":["Launch packer from a directory that earlier pipeline steps don't delete or recreate.","Ensure container WORKDIR exists for the process lifetime.","Avoid cd into ephemeral temp dirs cleaned mid-run."],"tags":["filesystem","sbom","provisioner"],"backgroundTag":"working-directory-missing","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"}