kataras/iris · error
template vars: <%s = %s>: %w
Error message
template vars: <%s = %s>: %w
What it means
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.
Source
Thrown at i18n/internal/template.go:48
*Message
tmpl *template.Template
bufPool *sync.Pool
}
// NewTemplate returns a new Template message based on the
// catalog and the base translation Message. See `Locale.Load` method.
func NewTemplate(c *Catalog, m *Message) (*Template, error) {
tmpl, err := template.New(m.Key).
Delims(m.Locale.Options.Left, m.Locale.Options.Right).
Funcs(m.Locale.FuncMap).
Parse(m.Value)
if err != nil {
return nil, err
}
if err := registerTemplateVars(c, m); err != nil {
return nil, fmt.Errorf("template vars: <%s = %s>: %w", m.Key, m.Value, err)
}
bufPool := &sync.Pool{
New: func() any {
return new(bytes.Buffer)
},
}
t := &Template{
Message: m,
tmpl: tmpl,
bufPool: bufPool,
}
return t, nil
}
func registerTemplateVars(c *Catalog, m *Message) error {View on GitHub (pinned to 7bedaf55a0)
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.
Example fix
// before
"welcome": "Hi {{name" // unbalanced
// after
"welcome": "Hi {{.name}}" Defensive patterns
Strategy: validation
Validate before calling
// validate template delimiters before load
for k, v := range pairs {
s, _ := v.(string)
if strings.Count(s, "{{") != strings.Count(s, "}}") {
return fmt.Errorf("key %q: unbalanced {{ }} delimiters", k)
}
if _, err := texttemplate.New(k).Parse(s); err != nil {
return fmt.Errorf("key %q: invalid template: %w", k, err)
}
} Try / catch
t, err := internal.NewTemplate(c, m)
if err != nil {
log.Printf("template vars failed for key=%q: %v", m.Key, err)
return fmt.Errorf("template vars: <%s = %s>: %w", m.Key, m.Value, err)
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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).
Related errors
- nil loader
- catalog: empty languages
- expected language index to be lower or equal than %d but got
- %s:%s parse string: %w
- %s:%s parse map: %w
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/c99e7c0dea8114fb.
Report an issue: GitHub.