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

  1. Use one of '+', '-', '*', '/' as the operator.
  2. For modulo, use Go's native % operator directly instead of DoArithmetic.
  3. 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

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


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)