gohugoio/hugo · error
there is no such an operation
Error message
there is no such an operation
What it means
The operator switch in DoArithmetic only handles + - * /. Any other rune passed as op reaches this default and is rejected. Hugo's own template helpers only ever pass those four operators, so this error almost always indicates a direct Go caller passing an unsupported operator constant.
Solutions
- Use one of '+', '-', '*', '/' as the operator.
- For modulo, use Go's native % operator directly instead of DoArithmetic.
- Don't reuse DoArithmetic for non-arithmetic operators; implement dedicated helpers.
Example fix
// before math.DoArithmetic(a, b, '%') // after a % b
Defensive patterns
Strategy: validation
Validate before calling
// Only + - * / are valid operators
switch op {
case '+', '-', '*', '/':
default:
return nil, fmt.Errorf("unsupported operator %q", op)
}
math.DoArithmetic(a, b, op) Type guard
func isValidArithOp(op rune) bool { return op == '+' || op == '-' || op == '*' || op == '/' } Prevention
- Restrict callers to the four supported operators.
- Use native Go operators for modulo/bitwise ops instead of DoArithmetic.
- Unit-test custom callers that pass operator constants.
When it happens
Trigger: A Go caller invoking math.DoArithmetic(a, b, '%') or '%'/'^'/'|' as the op rune instead of using native Go operators.
Common situations: Custom code reusing Hugo's math.DoArithmetic for modulo or bitwise ops; copy-paste errors in operator constants.
Related errors
- can't apply the operator to the values
- can't divide the value by 0
- abort: jekyll root contains neither posts nor drafts
- arguments must be slices or arrays
- arguments to complement must be slices or arrays
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/e4b32b43c396ef51.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)