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
- Pass a numeric value (int or float) to math.Acos.
- Add a numeric default: {{ math.Acos (.Param "x" | default 0) }}.
- Guard the call behind a type/numeric check on the source value.
- 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
- Pass numeric values to trig functions.
- Default unset params to a number.
- Keep source numeric fields unquoted.
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
- requires numeric arguments
- the math.Abs function requires a numeric argument
- Ceil operator can't be used with non-float value
- Floor operator can't be used with non-float value
- Log operator can't be used with non integer or float value
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/0154e9f75001cd4d.
Report an issue: GitHub.