{"record":{"id":"7ae21ae69fecd589","repo":"gohugoio/hugo","slug":"must-provide-at-least-two-numbers","errorCode":null,"errorMessage":"must provide at least two numbers","messagePattern":"must provide at least two numbers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":30,"sourceCode":"// limitations under the License.\n\n// Package math provides template functions for mathematical operations.\npackage math\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"math\"\n\t\"math/rand\"\n\t\"reflect\"\n\n\t_math \"github.com/gohugoio/hugo/common/math\"\n\t\"github.com/gohugoio/hugo/deps\"\n\t\"github.com/spf13/cast\"\n)\n\nvar (\n\terrMustTwoNumbersError = errors.New(\"must provide at least two numbers\")\n\terrMustOneNumberError  = errors.New(\"must provide at least one number\")\n)\n\n// New returns a new instance of the math-namespaced template functions.\nfunc New(d *deps.Deps) *Namespace {\n\treturn &Namespace{\n\t\td: d,\n\t}\n}\n\n// Namespace provides template functions for the \"math\" namespace.\ntype Namespace struct {\n\td *deps.Deps\n}\n\n// Abs returns the absolute value of n.\nfunc (ns *Namespace) Abs(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{{ $total := math.Add .Price }}\n\n// after\n{{ $total := math.Add .Price .Tax }}","handlingStrategy":"validation","validationCode":"// Provide at least two operands to Add/Sub/Mul/Div:\n{{ math.Add .Price .Tax }}\n// For single-operand sums over slices, use math.Sum instead:\n{{ math.Sum (slice 1 2 3) }}","typeGuard":"// Go caller of doArithmetic-backed functions:\nfunc enoughOperands(inputs []any) bool { return len(inputs) >= 2 }","tryCatchPattern":null,"preventionTips":["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."],"tags":["hugo","template","math","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}