{"record":{"id":"71e0bd486ab5964c","repo":"hashicorp/packer","slug":"error-interpolating-default-value-for-s-s","errorCode":null,"errorMessage":"error interpolating default value for '%s': %s","messagePattern":"error interpolating default value for '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/core.go","lineNumber":1016,"sourceCode":"\t\t\t\t// variables that still need interpolating for a repeat.\n\t\t\t\tdone, err := isDoneInterpolating(kv.Value)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn ctx, err\n\t\t\t\t}\n\t\t\t\tif done {\n\t\t\t\t\tdeleteKeys = append(deleteKeys, kv.Key)\n\t\t\t\t} else {\n\t\t\t\t\tshouldRetry = true\n\t\t\t\t}\n\t\t\tcase ttmp.ExecError:\n\t\t\t\tif strings.Contains(err.Error(), interpolate.ErrVariableNotSetString) {\n\t\t\t\t\tshouldRetry = true\n\t\t\t\t\tfailedInterpolation = fmt.Sprintf(`\"%s\": \"%s\"; error: %s`, kv.Key, kv.Value, err)\n\t\t\t\t} else {\n\t\t\t\t\treturn ctx, err\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn ctx, fmt.Errorf(\n\t\t\t\t\t// unexpected interpolation error: abort the run\n\t\t\t\t\t\"error interpolating default value for '%s': %s\",\n\t\t\t\t\tkv.Key, err)\n\t\t\t}\n\t\t}\n\t\tif !shouldRetry {\n\t\t\tbreak\n\t\t}\n\n\t\t// Clear completed vars from sortedMap before next loop. Do this one\n\t\t// key at a time because the indices are gonna change ever time you\n\t\t// delete from the map.\n\t\tfor _, k := range deleteKeys {\n\t\t\tfor ind, kv := range sortedMap {\n\t\t\t\tif kv.Key == k {\n\t\t\t\t\tsortedMap = append(sortedMap[:ind], sortedMap[ind+1:]...)\n\t\t\t\t\tbreak\n\t\t\t\t}","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/core.go#L998-L1034","documentation":"`renderVarsRecursively` interpolates each variable's default with `interpolate.RenderRegex` and switches on the error type. `nil` means success, `ttmp.ExecError` containing 'variable not set' triggers a retry loop, but any other error type is unexpected and aborts immediately with `error interpolating default value for '%s': %s`, naming the variable key and the underlying interpolation error. This indicates malformed template-engine syntax or a render failure that is not simply an unset user variable.","triggerScenarios":"Called during `Core.init()`; `interpolate.RenderRegex(kv.Value, ctx, renderFilter)` returns an error that is neither nil nor a `ttmp.ExecError` with the variable-not-set string — e.g. badly nested/unclosed `{{ }}` template blocks, unknown template functions, or other text-template parse/exec failures in a variable default.","commonSituations":"Typo in a template function inside a variable default (e.g. `{{timestampa}}`); unbalanced backticks or braces in `{{user `foo`}}`; copying shell-style `${}` syntax into a JSON template variable; escaping problems after migrating a template between JSON and HCL2.","solutions":["Look at the variable key named in the error and inspect its default value's `{{ }}` syntax for typos or unclosed braces/backticks.","Fix or remove the invalid template expression in the variable definition.","Confirm the function used exists in Packer's interpolation function list (e.g. `timestamp`, `env`, `user`) and is spelled correctly.","If the variable genuinely references an unset user variable, that case is handled separately — supply the value with `-var` so it resolves instead of erroring."],"exampleFix":"// before\n\"variables\": {\n  \"name\": \"{{user `base`}}-{{timestampa}}\"\n}\n// after\n\"variables\": {\n  \"name\": \"{{user `base`}}-{{timestamp}}\"\n}","handlingStrategy":"try-catch","validationCode":"// sanity-check a variable default's template syntax before building\nfor name, val := range variables {\n    if strings.Count(val, \"{{\") != strings.Count(val, \"}}\") ||\n       strings.Count(val, \"`\")%2 != 0 {\n        return fmt.Errorf(\"variable %s has unbalanced template syntax\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go: distinguish unexpected interpolation failures\nif err := core.Initialize(); err != nil {\n    if strings.Contains(err.Error(), \"error interpolating default value for\") {\n        // extract the key between quotes and surface a config-fix message\n        return fmt.Errorf(\"fix variable template syntax: %w\", err)\n    }\n    return err\n}","preventionTips":["Lint templates (`packer validate`) before every build to catch bad `{{ }}` syntax early.","Verify template function names against Packer's interpolation function docs.","Balance backticks and braces when editing variable defaults, especially in JSON templates.","Prefer HCL2 templates where editors provide syntax highlighting for interpolation blocks."],"tags":["packer","interpolation","template-syntax"],"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"}