{"record":{"id":"e4b32b43c396ef51","repo":"gohugoio/hugo","slug":"there-is-no-such-an-operation","errorCode":null,"errorMessage":"there is no such an operation","messagePattern":"there is no such an operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/math/math.go","lineNumber":131,"sourceCode":"\t\treturn au - bu, nil\n\tcase '*':\n\t\tif isInt {\n\t\t\treturn ai * bi, nil\n\t\t} else if isFloat {\n\t\t\treturn af * bf, nil\n\t\t}\n\t\treturn au * bu, nil\n\tcase '/':\n\t\tif isInt && bi != 0 {\n\t\t\treturn ai / bi, nil\n\t\t} else if isFloat && bf != 0 {\n\t\t\treturn af / bf, nil\n\t\t} else if isUint && bu != 0 {\n\t\t\treturn au / bu, nil\n\t\t}\n\t\treturn nil, errors.New(\"can't divide the value by 0\")\n\tdefault:\n\t\treturn nil, errors.New(\"there is no such an operation\")\n\t}\n}\n","sourceCodeStart":113,"sourceCodeEnd":134,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/common/math/math.go#L113-L134","documentation":"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.","triggerScenarios":"A Go caller invoking math.DoArithmetic(a, b, '%') or '%'/'^'/'|' as the op rune instead of using native Go operators.","commonSituations":"Custom code reusing Hugo's math.DoArithmetic for modulo or bitwise ops; copy-paste errors in operator constants.","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."],"exampleFix":"// before\nmath.DoArithmetic(a, b, '%')\n// after\na % b","handlingStrategy":"validation","validationCode":"// Only + - * / are valid operators\nswitch op {\ncase '+', '-', '*', '/':\ndefault:\n    return nil, fmt.Errorf(\"unsupported operator %q\", op)\n}\nmath.DoArithmetic(a, b, op)","typeGuard":"func isValidArithOp(op rune) bool { return op == '+' || op == '-' || op == '*' || op == '/' }","tryCatchPattern":null,"preventionTips":["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."],"tags":["math","go","internal","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}