gohugoio/hugo · error

illegal number syntax: %q

Error message

illegal number syntax: %q

What it means

The template numeric literal could not be parsed as int, uint, or float - none of the parse paths succeeded, so newNumber returns illegal number syntax. See node.go:713-715.

Source

Thrown at tpl/internal/go_templates/texttemplate/parse/node.go:714

			// it's a huge number too large to fit in an int. Reject it.
			if !strings.ContainsAny(text, ".eEpP") {
				return nil, fmt.Errorf("integer overflow: %q", text)
			}
			n.IsFloat = true
			n.Float64 = f
			// If a floating-point extraction succeeded, extract the int if needed.
			if !n.IsInt && float64(int64(f)) == f {
				n.IsInt = true
				n.Int64 = int64(f)
			}
			if !n.IsUint && float64(uint64(f)) == f {
				n.IsUint = true
				n.Uint64 = uint64(f)
			}
		}
	}
	if !n.IsInt && !n.IsUint && !n.IsFloat {
		return nil, fmt.Errorf("illegal number syntax: %q", text)
	}
	return n, nil
}

// simplifyComplex pulls out any other types that are represented by the complex number.
// These all require that the imaginary part be zero.
func (n *NumberNode) simplifyComplex() {
	n.IsFloat = imag(n.Complex128) == 0
	if n.IsFloat {
		n.Float64 = real(n.Complex128)
		n.IsInt = float64(int64(n.Float64)) == n.Float64
		if n.IsInt {
			n.Int64 = int64(n.Float64)
		}
		n.IsUint = float64(uint64(n.Float64)) == n.Float64
		if n.IsUint {
			n.Uint64 = uint64(n.Float64)
		}

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Correct the numeric literal to valid Go constant syntax.
  2. Remove stray characters and fix decimal/thousand separators.
  3. Wrap intended non-numeric text in quotes so it is not parsed as a number.

Example fix

// before
{{ 1,000 }}

// after
{{ 1000 }}
Defensive patterns

Strategy: try-catch

Try / catch

treeSet, err := parse.Parse(name, text, left, right, funcs)
if err != nil {
    // err already formatted as template: name:line: msg
    return err
}

Prevention

When it happens

Trigger: Malformed literals such as {{ 0xZZ }}, {{ 1..2 }}, {{ 0b2 }}, or locale-formatted numbers with commas like {{ 1,000 }}.

Common situations: Typo in a numeric literal; copy-pasting locale-formatted numbers; stray punctuation inside an action; attempting unsupported base prefixes.

Related errors


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