{"record":{"id":"c99e7c0dea8114fb","repo":"kataras/iris","slug":"template-vars-s-s-w","errorCode":null,"errorMessage":"template vars: <%s = %s>: %w","messagePattern":"template vars: <(.+?) = (.+?)>: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"i18n/internal/template.go","lineNumber":48,"sourceCode":"\t*Message\n\ttmpl    *template.Template\n\tbufPool *sync.Pool\n}\n\n// NewTemplate returns a new Template message based on the\n// catalog and the base translation Message. See `Locale.Load` method.\nfunc NewTemplate(c *Catalog, m *Message) (*Template, error) {\n\ttmpl, err := template.New(m.Key).\n\t\tDelims(m.Locale.Options.Left, m.Locale.Options.Right).\n\t\tFuncs(m.Locale.FuncMap).\n\t\tParse(m.Value)\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err := registerTemplateVars(c, m); err != nil {\n\t\treturn nil, fmt.Errorf(\"template vars: <%s = %s>: %w\", m.Key, m.Value, err)\n\t}\n\n\tbufPool := &sync.Pool{\n\t\tNew: func() any {\n\t\t\treturn new(bytes.Buffer)\n\t\t},\n\t}\n\n\tt := &Template{\n\t\tMessage: m,\n\t\ttmpl:    tmpl,\n\t\tbufPool: bufPool,\n\t}\n\n\treturn t, nil\n}\n\nfunc registerTemplateVars(c *Catalog, m *Message) error {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/i18n/internal/template.go#L30-L66","documentation":"When a message value looks like a template (contains delimiters like {{ }}), setString builds a Template renderer via NewTemplate, which first calls registerTemplateVars to parse and register the template variables. If that fails, the error is wrapped as \"template vars: <key = value>: err\". It means a template-style message has invalid variable syntax or an invalid underlying template body.","triggerScenarios":"Loading/Set-ing a message whose value contains the configured Left/Right delimiters (default {{ }}) but fails template variable parsing — unbalanced braces, invalid variable names, or errors from the underlying template engine (text/template).","commonSituations":"Translation files with HTML/template or fmt-style placeholders that conflict with the {{ }} delimiters, typos like {{name} } , or escaping issues where literal braces were intended (e.g. JSON examples in messages).","solutions":["Fix the template braces/variable syntax reported by the wrapped inner error.","Escape or reconfigure delimiters via LoaderConfig Left/Right if your messages legitimately contain {{ }}.","Rename variables to valid identifiers and use consistent {{.Var}} style.","Test the message value as a standalone text/template to reproduce the exact parse error."],"exampleFix":"// before\n\"welcome\": \"Hi {{name\" // unbalanced\n// after\n\"welcome\": \"Hi {{.name}}\"","handlingStrategy":"validation","validationCode":"// validate template delimiters before load\nfor k, v := range pairs {\n    s, _ := v.(string)\n    if strings.Count(s, \"{{\") != strings.Count(s, \"}}\") {\n        return fmt.Errorf(\"key %q: unbalanced {{ }} delimiters\", k)\n    }\n    if _, err := texttemplate.New(k).Parse(s); err != nil {\n        return fmt.Errorf(\"key %q: invalid template: %w\", k, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"t, err := internal.NewTemplate(c, m)\nif err != nil {\n    log.Printf(\"template vars failed for key=%q: %v\", m.Key, err)\n    return fmt.Errorf(\"template vars: <%s = %s>: %w\", m.Key, m.Value, err)\n}","preventionTips":["Escape literal braces or change Left/Right delimiters via LoaderConfig.","Keep variable names simple identifiers in {{.Var}} form.","Lint translation files with a text/template parse step in CI.","Prefer simple variables over complex template logic in messages."],"tags":["i18n","go","template","syntax"],"backgroundTag":"template-parse-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}