gohugoio/hugo · error

requires a numeric argument

Error message

requires a numeric argument

What it means

Thrown by math.Acos (tpl/math/math.go:60) when its argument cannot be converted to float64. Acos computes the arccosine in radians and requires a numeric input; any non-numeric value (non-numeric string, nil, bool, struct, slice) triggers this generic numeric-argument error.

Source

Thrown at tpl/math/math.go:60

type Namespace struct {
	d *deps.Deps
}

// Abs returns the absolute value of n.
func (ns *Namespace) Abs(n any) (float64, error) {
	af, err := cast.ToFloat64E(n)
	if err != nil {
		return 0, errors.New("the math.Abs function requires a numeric argument")
	}

	return math.Abs(af), nil
}

// Acos returns the arccosine, in radians, of n.
func (ns *Namespace) Acos(n any) (float64, error) {
	af, err := cast.ToFloat64E(n)
	if err != nil {
		return 0, errors.New("requires a numeric argument")
	}
	return math.Acos(af), nil
}

// Add adds the multivalued addends n1 and n2 or more values.
func (ns *Namespace) Add(inputs ...any) (any, error) {
	return ns.doArithmetic(inputs, '+')
}

// Asin returns the arcsine, in radians, of n.
func (ns *Namespace) Asin(n any) (float64, error) {
	af, err := cast.ToFloat64E(n)
	if err != nil {
		return 0, errors.New("requires a numeric argument")
	}
	return math.Asin(af), nil
}

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Pass a numeric value (int or float) to math.Acos.
  2. Add a numeric default: {{ math.Acos (.Param "x" | default 0) }}.
  3. Guard the call behind a type/numeric check on the source value.
  4. Fix the source field to be numeric.

Example fix

// before
{{ math.Acos .Params.angle }}

// after
{{ $a := .Params.angle | default 0 }}
{{ math.Acos $a }}
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate numeric input before math.Acos:
{{ $v := .Param "x" | default 0 }}
{{ math.Acos $v }}

Type guard

// See errorIndex 148 for isNumeric; reuse it before calling math.Acos.

Prevention

When it happens

Trigger: Calling {{ math.Acos .Value }} where .Value is a non-numeric string, nil, bool, or aggregate type; piping a text field into the trig function.

Common situations: Using a template field that holds text instead of a number; nil from an unset param; assuming a quoted numeric string auto-converts when it does not.

Related errors


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