gohugoio/hugo · error
must provide at least two numbers
Error message
must provide at least two numbers
What it means
Defined as errMustTwoNumbersError (tpl/math/math.go:30) and returned by doArithmetic when fewer than two inputs are supplied. It backs the variadic Add, Sub, Mul, and Div functions, which require at least two operands to perform a binary operation.
Source
Thrown at tpl/math/math.go:30
// limitations under the License.
// Package math provides template functions for mathematical operations.
package math
import (
"errors"
"fmt"
"math"
"math/rand"
"reflect"
_math "github.com/gohugoio/hugo/common/math"
"github.com/gohugoio/hugo/deps"
"github.com/spf13/cast"
)
var (
errMustTwoNumbersError = errors.New("must provide at least two numbers")
errMustOneNumberError = errors.New("must provide at least one number")
)
// New returns a new instance of the math-namespaced template functions.
func New(d *deps.Deps) *Namespace {
return &Namespace{
d: d,
}
}
// Namespace provides template functions for the "math" namespace.
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)View on GitHub (pinned to 52c9bd7908)
Solutions
- Supply at least two numeric arguments: {{ math.Add 1 2 }}.
- For increments, pass an explicit second operand: {{ math.Add .Count 1 }}.
- When piping, ensure the piped value plus at least one positional arg are both present: {{ math.Add .X 1 }} with .X on the left of the pipe.
- Use math.Sum (which accepts one or more via slices) if you need single-operand summation behavior.
Example fix
// before
{{ $total := math.Add .Price }}
// after
{{ $total := math.Add .Price .Tax }} Defensive patterns
Strategy: validation
Validate before calling
// Provide at least two operands to Add/Sub/Mul/Div:
{{ math.Add .Price .Tax }}
// For single-operand sums over slices, use math.Sum instead:
{{ math.Sum (slice 1 2 3) }} Type guard
// Go caller of doArithmetic-backed functions:
func enoughOperands(inputs []any) bool { return len(inputs) >= 2 } Prevention
- Always pass at least two numeric operands to Add, Sub, Mul, Div.
- When piping, ensure a positional operand accompanies the piped value.
- Use math.Sum/Product/Min/Max for slice-based variadic math.
When it happens
Trigger: Calling {{ math.Add 5 }} (one arg), {{ math.Mul }} (zero args), or piping nothing into {{ .X | math.Add }} so only one value arrives. Sub/Div are not commutative so a single operand is ambiguous and rejected.
Common situations: Piping into math.Add expecting it to behave like an increment; forgetting the second operand in a template; refactoring a list and ending up with a single-element slice piped to a variadic op.
Related errors
- can't divide the value by 0
- invalid number of arguments to Seq
- invalid arguments to Seq
- both count and seq must be provided
- complement needs at least two arguments
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/7ae21ae69fecd589.
Report an issue: GitHub.