gohugoio/hugo · error
there is no such an operation
Error message
there is no such an operation
What it means
DoArithmetic accepts an operator as a rune and only implements '+', '-', '*', and '/'. Any other rune reaches the default case at common/math/math.go:131 and returns this error. In practice user templates can't pass arbitrary operators (add/sub/mul/div hardcode them), so this surfaces mainly from internal or programmatic callers passing an unsupported op.
Source
Thrown at common/math/math.go:131
return au - bu, nil
case '*':
if isInt {
return ai * bi, nil
} else if isFloat {
return af * bf, nil
}
return au * bu, nil
case '/':
if isInt && bi != 0 {
return ai / bi, nil
} else if isFloat && bf != 0 {
return af / bf, nil
} else if isUint && bu != 0 {
return au / bu, nil
}
return nil, errors.New("can't divide the value by 0")
default:
return nil, errors.New("there is no such an operation")
}
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Use one of the supported operators: '+', '-', '*', '/'.
- For modulo in templates use `mod`/`math.Mod`; for powers use `math.Pow` — DoArithmetic does not implement them.
- If extending Hugo, add the operator case to the switch in DoArithmetic rather than passing an unhandled rune.
Example fix
// before res, err := math.DoArithmetic(a, b, '%') // after res, err := math.DoArithmetic(a, b, '/') // or use the dedicated mod helpers
Defensive patterns
Strategy: validation
Validate before calling
validOps := map[rune]bool{'+': true, '-': true, '*': true, '/': true}
if !validOps[op] { /* reject before calling */ } Try / catch
v, err := math.DoArithmetic(a, b, op)
if err != nil {
// unknown operator: programming error — fail fast, fix the call site
} Prevention
- Pass only the supported operator runes '+', '-', '*', '/'.
- If operators come from config or user input, whitelist them at the trust boundary.
- Prefer the named template funcs (add, sub, mul, div) over building operator characters dynamically.
When it happens
Trigger: Calling common/math.DoArithmetic (directly from Go code, a fork, or a custom build) with an op rune other than '+', '-', '*', '/' — e.g. '%' for modulo or '^' for power.
Common situations: Custom Hugo forks or Go code reusing the math package and expecting modulo/power support; modulo in templates must use the separate `mod`/`math.Mod` functions, not DoArithmetic.
Related errors
- errMustTwoNumbersError
- errMustOneNumberError
- the math.Abs function requires a numeric argument
- Ceil operator can't be used with non-float value
- Floor operator can't be used with non-float value
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/e4b32b43c396ef51.json.
Report an issue: GitHub ↗.