{"record":{"id":"4a597d77616acb77","repo":"hashicorp/nomad","slug":"generated-unexpected-hil-type-s","errorCode":null,"errorMessage":"generated unexpected hil type: %s","messagePattern":"generated unexpected hil type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/auth/binder.go","lineNumber":220,"sourceCode":"\t\tvm[k] = ast.Variable{\n\t\t\tType:  ast.TypeString,\n\t\t\tValue: v,\n\t\t}\n\t}\n\n\tconfig := &hil.EvalConfig{\n\t\tGlobalScope: &ast.BasicScope{\n\t\t\tVarMap: vm,\n\t\t},\n\t}\n\n\tresult, err := hil.Eval(tree, config)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif result.Type != hil.TypeString {\n\t\treturn \"\", fmt.Errorf(\"generated unexpected hil type: %s\", result.Type)\n\t}\n\n\treturn result.Value.(string), nil\n}\n","sourceCodeStart":202,"sourceCodeEnd":225,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/lib/auth/binder.go#L202-L225","documentation":"InterpolateHIL evaluates a bind-name or token-name template with HIL and expects a string result. If HIL returns a non-string type (e.g. the template evaluates arithmetic/boolean expressions), this error is thrown.","triggerScenarios":"A BindName or token name template whose HIL expression evaluates to a number or boolean, e.g. \"${1 + 1}\" or a variable inserted as a non-string ast.Variable by a caller.","commonSituations":"Copy-pasted HIL from Terraform using expressions instead of plain string interpolation; template with only a numeric expression and no surrounding text.","solutions":["Rewrite the template so the expression yields a string (wrap in quotes or literal text)","Use only string-typed claim variables in the template","Simplify the template to plain literals and ${claim} substitutions"],"exampleFix":"// before\nBindName: \"${1 + 1}\"\n// after\nBindName: \"team-${index}\" // where index is a string claim mapping","handlingStrategy":"validation","validationCode":"// reject templates that are pure expressions without literal text\nfunc isPlainStringTemplate(tmpl string) bool {\n    return !regexp.MustCompile(`^\\$\\{[^}]*\\}$`).MatchString(tmpl)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unexpected hil type\") {\n    return fmt.Errorf(\"bind template must evaluate to a string: %w\", err)\n}","preventionTips":["Use only ${stringVar} substitutions, never arithmetic or boolean HIL expressions","Surround interpolations with literal text so the result is always a string","Review templates copied from Terraform for HIL expression features"],"tags":["auth","hil","template-interpolation"],"backgroundTag":"hil-type-mismatch","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}