gohugoio/hugo · error
missing arguments for comparison
Error message
missing arguments for comparison
What it means
Thrown by Namespace.checkComparisonArgCount (compare.go:224-228) when a comparison function is called with fewer than the required number of additional arguments. Eq/Ne/Gt/Ge/Lt/Le/LtCollate each require at least one `other` value to compare against the first.
Source
Thrown at tpl/compare/compare.go:226
func (n *Namespace) LtCollate(collator *langs.Collator, first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
left, right := n.compareGetWithCollator(collator, first, other)
if !(left < right) {
return false
}
}
return true
}
// Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.
func (n *Namespace) Lt(first any, others ...any) bool {
return n.LtCollate(nil, first, others...)
}
func (n *Namespace) checkComparisonArgCount(min int, others ...any) bool {
if len(others) < min {
panic("missing arguments for comparison")
}
return true
}
// Conditional can be used as a ternary operator.
//
// It returns v1 if cond is true, else v2.
func (n *Namespace) Conditional(cond any, v1, v2 any) any {
if hreflect.IsTruthful(cond) {
return v1
}
return v2
}
func (ns *Namespace) compareGet(a any, b any) (float64, float64) {
return ns.compareGetWithCollator(nil, a, b)
}
View on GitHub (pinned to 52c9bd7908)
Solutions
- Provide at least two operands to every comparison function.
- Guard the call so the second operand exists before invoking gt/lt/eq/etc.
- Use with/if blocks to ensure the value is present.
Example fix
// before
{{ if gt $x }}yes{{ end }}
// after
{{ if gt $x 1 }}yes{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{ with $y }}
{{ if gt $x . }}yes{{ end }}
{{ end }} Prevention
- Always pass at least two operands to comparison functions.
- Use with/if to ensure the second operand is present.
- Static-lint templates for bare single-arg comparisons.
When it happens
Trigger: Calling gt, lt, ge, le, eq, or ne with only one argument, or with no arguments, e.g. {{ gt 5 }}. The variadic `others` slice is shorter than the minimum (1).
Common situations: A template variable meant to supply the second operand is empty/nil and the function is invoked unconditionally; refactoring a conditional removes the second argument by mistake.
Related errors
- size of result exceeds limit
- 'increment' must not be 0
- 'increment' must be > 0
- 'increment' must be < 0
- config needs a filename
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/e98de45447d3cea9.
Report an issue: GitHub.