{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L121-L157","documentation":"Thrown by math.Log (tpl/math/math.go:139) when its argument cannot be converted to float64. Log computes the natural logarithm and requires a numeric input. (Despite the message mentioning 'integer or float', the implementation simply tries cast.ToFloat64E.)","triggerScenarios":"Calling {{ math.Log .Value }} with a non-numeric string, nil, bool, struct, or slice. Note also that Log(0) or negative inputs return -Inf/NaN without an error from this check, so domain issues are separate.","commonSituations":"Unset param (nil); text field mistaken for a number; passing 0 or negative numbers and then being surprised by Inf/NaN downstream.","solutions":["Pass a positive numeric value to math.Log.","Add a numeric default and guard against <= 0 if Inf/NaN would break downstream rendering.","Validate the source field is numeric and positive.","Fix the source data."],"exampleFix":"// before\n{{ math.Log .Params.rate }}\n\n// after\n{{ $r := .Params.rate | default 1 }}\n{{ if gt $r 0 }}{{ math.Log $r }}{{ end }}","handlingStrategy":"validation","validationCode":"// Validate numeric AND positive input before math.Log (Log(0) gives -Inf):\n{{ $r := .Param \"rate\" | default 1 }}\n{{ if gt $r 0 }}{{ math.Log $r }}{{ end }}","typeGuard":"// Go caller:\nfunc positiveNumber(v any) bool {\n    f, err := cast.ToFloat64E(v)\n    return err == nil && f > 0\n}","tryCatchPattern":null,"preventionTips":["Pass a positive numeric value to math.Log.","Guard against <= 0 to avoid Inf/NaN in downstream rendering.","Default unset params to 1, not 0."],"tags":["hugo","template","math","type-validation","logarithm"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}