glanceapp/glance · error

parsing template: %w

Error message

parsing template: %w

What it means

Returned by customAPIWidget.initialize when template.New("").Funcs(customAPITemplateFuncs).Parse(widget.Template) fails, i.e. the widget's template string is syntactically invalid Go template text. This is a parse-time error, distinct from execution errors: the template never compiled.

Source

Thrown at internal/glance/widget-custom-api.go:70

	widget.withTitle("Custom API").withCacheDuration(1 * time.Hour)

	if err := widget.CustomAPIRequest.initialize(); err != nil {
		return fmt.Errorf("initializing primary request: %v", err)
	}

	for key := range widget.Subrequests {
		if err := widget.Subrequests[key].initialize(); err != nil {
			return fmt.Errorf("initializing subrequest %q: %v", key, err)
		}
	}

	if widget.Template == "" {
		return errors.New("template is required")
	}

	compiledTemplate, err := template.New("").Funcs(customAPITemplateFuncs).Parse(widget.Template)
	if err != nil {
		return fmt.Errorf("parsing template: %w", err)
	}

	widget.compiledTemplate = compiledTemplate

	return nil
}

func (widget *customAPIWidget) update(ctx context.Context) {
	compiledHTML, err := fetchAndRenderCustomAPIRequest(
		widget.CustomAPIRequest, widget.Subrequests, widget.Options, widget.compiledTemplate,
	)
	if !widget.canContinueUpdateAfterHandlingErr(err) {
		return
	}

	widget.CompiledHTML = compiledHTML
}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Check the wrapped parse error: text/template reports the offending line/column of the template string.
  2. Balance every {{if}}/{{range}}/{{with}} with {{end}} and close every {{ }} action.
  3. In YAML use a literal block (template: |) with consistent indentation so braces survive parsing.
  4. Paste the template into a Go playground with template.New("t").Parse to validate syntax quickly.

Example fix

# before
template: >-
  {{ if .JSON.hello }} hello {{ end  -- missing brace

# after
template: >-
  {{ if .JSON.hello }}hello{{ end }}
Defensive patterns

Strategy: validation

Validate before calling

// pre-parse templates in CI or a config check
_, err := template.New("").Funcs(customAPITemplateFuncs).Parse(cfg.Template)
if err != nil {
    return fmt.Errorf("custom-api template does not parse: %w", err)
}

Try / catch

compiled, err := template.New("").Funcs(customAPITemplateFuncs).Parse(tpl)
if err != nil {
    return fmt.Errorf("parsing template: %w", err) // parse error = config bug, do not retry
}

Prevention

When it happens

Trigger: Unclosed action {{ .Foo without }}, unmatched {{if}}/{{end}} or {{range}}/{{end}}, invalid pipeline syntax like {{ .A | }}, or a malformed function call.

Common situations: Hand-editing the template block in YAML; YAML stripping or mangling braces due to quoting/indentation; copying a template that uses different delimiters; truncation by a multiline block scalar mistake (| vs >).

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/9aa735fefcba1fde. Report an issue: GitHub.