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

  1. Fix the template braces/variable syntax reported by the wrapped inner error.
  2. Escape or reconfigure delimiters via LoaderConfig Left/Right if your messages legitimately contain {{ }}.
  3. Rename variables to valid identifiers and use consistent {{.Var}} style.
  4. 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

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


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/c99e7c0dea8114fb. Report an issue: GitHub.