gohugoio/hugo · error

template: %s:%d: %s

Error message

template: %s:%d: %s

What it means

This is the universal prefix the parser attaches to every parse error: 'template: <ParseName>:<line>: <message>'. It is the formatting wrapper in Tree.errorf (parse.go:173-177), not a distinct error; the specific failure (704, 705, 706, undefined function, unexpected token, etc.) is interpolated into the trailing %s.

Source

Thrown at tpl/internal/go_templates/texttemplate/parse/parse.go:176

	}
	text := tree.text[:pos]
	byteNum := strings.LastIndex(text, "\n")
	if byteNum == -1 {
		byteNum = pos // On first line.
	} else {
		byteNum++ // After the newline.
		byteNum = pos - byteNum
	}
	lineNum := 1 + strings.Count(text, "\n")
	context = n.String()
	return fmt.Sprintf("%s:%d:%d", tree.ParseName, lineNum, byteNum), context
}

// errorf formats the error and terminates processing.
func (t *Tree) errorf(format string, args ...any) {
	t.Root = nil
	format = fmt.Sprintf("template: %s:%d: %s", t.ParseName, t.token[0].line, format)
	panic(fmt.Errorf(format, args...))
}

// error terminates processing.
func (t *Tree) error(err error) {
	t.errorf("%s", err)
}

// expect consumes the next token and guarantees it has the required type.
func (t *Tree) expect(expected itemType, context string) item {
	token := t.nextNonSpace()
	if token.typ != expected {
		t.unexpected(token, context)
	}
	return token
}

// expectOneOf consumes the next token and guarantees it has one of the required types.
func (t *Tree) expectOneOf(expected1, expected2 itemType, context string) item {

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Read the file:line:column in the formatted message to locate the actual source position.
  2. Fix the underlying specific error described after the line number.
  3. Run a template linter or formatter to catch structural mistakes early.
Defensive patterns

Strategy: try-catch

Try / catch

_, err := template.New(name).Parse(text)
if err != nil {
    // err string starts with "template: <name>:<line>:"
    log.Printf("template parse failed: %v", err)
    return err
}

Prevention

When it happens

Trigger: Any syntax or parse-time error in a Go template: unbalanced delimiters, missing {{end}}, unclosed action, bad node, undefined function reference during parse.

Common situations: Authoring typo in a template; forgetting to close a range/with/if block; this carrier string precedes nearly every build-time template parse error.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/f3ecb6070f2c82ec. Report an issue: GitHub.