{"record":{"id":"e98de45447d3cea9","repo":"gohugoio/hugo","slug":"missing-arguments-for-comparison","errorCode":null,"errorMessage":"missing arguments for comparison","messagePattern":"missing arguments for comparison","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/compare/compare.go","lineNumber":226,"sourceCode":"func (n *Namespace) LtCollate(collator *langs.Collator, first any, others ...any) bool {\n\tn.checkComparisonArgCount(1, others...)\n\tfor _, other := range others {\n\t\tleft, right := n.compareGetWithCollator(collator, first, other)\n\t\tif !(left < right) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n// Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.\nfunc (n *Namespace) Lt(first any, others ...any) bool {\n\treturn n.LtCollate(nil, first, others...)\n}\n\nfunc (n *Namespace) checkComparisonArgCount(min int, others ...any) bool {\n\tif len(others) < min {\n\t\tpanic(\"missing arguments for comparison\")\n\t}\n\treturn true\n}\n\n// Conditional can be used as a ternary operator.\n//\n// It returns v1 if cond is true, else v2.\nfunc (n *Namespace) Conditional(cond any, v1, v2 any) any {\n\tif hreflect.IsTruthful(cond) {\n\t\treturn v1\n\t}\n\treturn v2\n}\n\nfunc (ns *Namespace) compareGet(a any, b any) (float64, float64) {\n\treturn ns.compareGetWithCollator(nil, a, b)\n}\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/compare/compare.go#L208-L244","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n{{ if gt $x }}yes{{ end }}\n// after\n{{ if gt $x 1 }}yes{{ end }}","handlingStrategy":"validation","validationCode":"{{ with $y }}\n  {{ if gt $x . }}yes{{ end }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["template","compare","validation","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}