{"record":{"id":"55c9a65be411e208","repo":"hashicorp/packer","slug":"error-parsing-output-dir-template-w","errorCode":null,"errorMessage":"error parsing output_dir template: %w","messagePattern":"error parsing output_dir template: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/provenance/post-processor.go","lineNumber":158,"sourceCode":"\tif p.config.SBOMFormat == \"\" {\n\t\tp.config.SBOMFormat = string(internalsbom.FormatCycloneDX)\n\t}\n\tif p.config.SBOMScope == \"\" {\n\t\tp.config.SBOMScope = internalsbom.ScopeSquashed\n\t}\n\tif p.config.SigningMode == \"\" {\n\t\tp.config.SigningMode = internalattestation.SigningModeNone\n\t}\n\tif p.config.FulcioURL == \"\" {\n\t\tp.config.FulcioURL = \"https://fulcio.sigstore.dev\"\n\t}\n\tif p.config.RekorURL == \"\" {\n\t\tp.config.RekorURL = \"https://rekor.sigstore.dev\"\n\t}\n\n\tif p.config.OutputDir != \"\" {\n\t\tif err := interpolate.Validate(p.config.OutputDir, &p.config.ctx); err != nil {\n\t\t\treturn fmt.Errorf(\"error parsing output_dir template: %w\", err)\n\t\t}\n\t}\n\n\tif _, err := p.signingBackendConfig(); err != nil {\n\t\treturn err\n\t}\n\n\tif p.generateSBOM == nil {\n\t\tp.generateSBOM = func(ctx context.Context, cfg internalsbom.Config) ([]byte, error) {\n\t\t\treturn internalsbom.NewGenerator(cfg).Generate(ctx)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, source packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {\n\tif p.config.Provenance.False() {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/provenance/post-processor.go#L140-L176","documentation":"During Configure, the provenance post-processor validates the `output_dir` string with `interpolate.Validate` before any build runs. Malformed template syntax (unbalanced braces, unknown functions, invalid variable names) returns `error parsing output_dir template: %w`. Configure fails immediately, so the build never starts.","triggerScenarios":"Setting `output_dir` in the provenance post-processor to a value like `out/{{ .BuildName` (unclosed `{{`) or using an unknown function `{{ notAFunction \"x\" }}`. The error surfaces as a Configure failure at the start of `packer build`.","commonSituations":"Typos in template functions; HCL2 strings where `{{` must be escaped as `{{` inside quotes plus `%{` for directives confusion; porting JSON-templates syntax into HCL2.","solutions":["Fix the template syntax in `output_dir`; ensure `{{ .Variable }}` style with balanced braces.","Run `packer validate` to check the template before building.","Read the wrapped error after the colon for the exact parse offset/function.","If you don't need templating, use a plain literal path with no `{{ }}` at all."],"exampleFix":"// before\noutput_dir = \"attestations/{{ .BuildName\"\n// after\noutput_dir = \"attestations/${build.name}\"","handlingStrategy":"validation","validationCode":"// validate output_dir template at config-load time\nif err := interpolate.Validate(cfg.OutputDir, &ctx); err != nil {\n    return fmt.Errorf(\"bad output_dir: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Configure already returns the error; just fail fast with context\nif err := pp.Configure(raws); err != nil {\n    return fmt.Errorf(\"provenance config rejected: %w\", err)\n}","preventionTips":["Run `packer validate` before every build.","Avoid hand-writing `{{ }}` templates; copy known-good examples.","Use plain literal paths when templating isn't needed.","Escape braces if you need literal `{{` in output paths."],"tags":["interpolation","validation","configuration","provenance"],"backgroundTag":"template-interpolation-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"}