{"id":"f90732f7d8e4438f","repo":"gohugoio/hugo","slug":"log-operator-can-t-be-used-with-non-integer-or-flo","errorCode":null,"errorMessage":"Log operator can't be used with non integer or float value","messagePattern":"Log operator can't be used with non integer or float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":139,"sourceCode":"func (ns *Namespace) Div(inputs ...any) (any, error) {\n\treturn ns.doArithmetic(inputs, '/')\n}\n\n// Floor returns the greatest integer value less than or equal to n.\nfunc (ns *Namespace) Floor(n any) (float64, error) {\n\txf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Floor operator can't be used with non-float value\")\n\t}\n\n\treturn math.Floor(xf), nil\n}\n\n// Log returns the natural logarithm of the number n.\nfunc (ns *Namespace) Log(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Log operator can't be used with non integer or float value\")\n\t}\n\n\treturn math.Log(af), nil\n}\n\n// Max returns the greater of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Max(inputs ...any) (maximum float64, err error) {\n\treturn ns.applyOpToScalarsOrSlices(\"Max\", math.Max, inputs...)\n}\n\n// MaxInt64 returns the maximum value for a signed 64-bit integer.\nfunc (ns *Namespace) MaxInt64() int64 {\n\treturn math.MaxInt64\n}\n\n// Min returns the smaller of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Min(inputs ...any) (minimum float64, err error) {\n\treturn ns.applyOpToScalarsOrSlices(\"Min\", math.Min, inputs...)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/math/math.go#L121-L157","documentation":"math.Log computes the natural logarithm after casting the argument to float64; if the cast fails, this error is returned. It flags a type error in the input — note that a valid numeric input that is negative or zero will not raise this error but will return NaN/-Inf per Go's math.Log semantics.","triggerScenarios":"`{{ math.Log \"ten\" }}` or `{{ math.Log .Params.count }}` where the param is nil, a non-numeric string, or a collection — anything cast.ToFloat64E rejects.","commonSituations":"Tag-cloud or weight-scaling templates (`math.Log .Count`-style) applied to values sourced from data files or params that are strings or missing; passing the result of a lookup that returned nil.","solutions":["Pass a numeric argument: `{{ math.Log 10 }}`.","Convert or default first: `{{ math.Log (float (.Params.count | default 1)) }}`.","Separately guard against zero/negative inputs if NaN or -Inf in output would break downstream formatting."],"exampleFix":"<!-- before -->\n{{ math.Log .Params.count }}\n<!-- after -->\n{{ math.Log (float (.Params.count | default 1)) }}","handlingStrategy":"type-guard","validationCode":"{{ $v := .Params.count }}\n{{ $f := float $v }}\n{{ if gt $f 0 }}{{ math.Log $f }}{{ end }}","typeGuard":"{{ with try (float $v) }}{{ if not .Err }}{{ math.Log .Value }}{{ end }}{{ end }}","tryCatchPattern":"{{ with try (math.Log $v) }}{{ if .Err }}{{ warnf \"Log needs a number: %s\" .Err }}{{ else }}{{ .Value }}{{ end }}{{ end }}","preventionTips":["math.Log accepts ints and floats only — cast strings with `float`/`int` first","Also guard the domain: pass a positive value or you'll get NaN/-Inf even after the type check","Cast shortcode string params before any math function"],"tags":["hugo","templates","math","type-conversion","logarithm"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}