{"record":{"id":"567af4503d40f2ee","repo":"dianping/cat","slug":"fun-is-not-a-function","errorCode":null,"errorMessage":"{fun} is not a function","messagePattern":"(.+?) is not a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":49105,"sourceCode":"        }\n\n        for (var i = 0; i < length; i++) {\n            if (i in self && fun.call(thisp, self[i], i, object)) {\n                return true;\n            }\n        }\n        return false;\n    };\n}\nif (!Array.prototype.reduce) {\n    Array.prototype.reduce = function reduce(fun /*, initial*/) {\n        var object = toObject(this),\n            self = splitString && _toString(this) == \"[object String]\" ?\n                this.split(\"\") :\n                object,\n            length = self.length >>> 0;\n        if (_toString(fun) != \"[object Function]\") {\n            throw new TypeError(fun + \" is not a function\");\n        }\n        if (!length && arguments.length == 1) {\n            throw new TypeError(\"reduce of empty array with no initial value\");\n        }\n\n        var i = 0;\n        var result;\n        if (arguments.length >= 2) {\n            result = arguments[1];\n        } else {\n            do {\n                if (i in self) {\n                    result = self[i++];\n                    break;\n                }\n                if (++i >= length) {\n                    throw new TypeError(\"reduce of empty array with no initial value\");\n                }","sourceCodeStart":49087,"sourceCodeEnd":49123,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L49087-L49123","documentation":"This TypeError comes from the ES5 shim bundled into worker-xquery.js: a fallback Array.prototype.reduce installed only when the environment lacks native reduce. It throws when the first argument is not callable ('fun + \" is not a function\"'), matching the ES5 requirement that reduce's callback be a function. In modern browsers the native method is used, but the identical error still occurs with the same cause.","triggerScenarios":"Calling array.reduce(null), array.reduce('sum'), array.reduce(someUndefined), or passing a property that is not a function (e.g. obj.callback where callback is missing) inside the worker or any code it loads.","commonSituations":"Passing an undefined method name; conditionally defined callbacks (if (x) cb = ...) that end up undefined; API changes where reduce was added/renamed; string 'sum' instead of a function reference.","solutions":["Pass an actual function: arr.reduce(function(acc, v) { return acc + v; }, 0).","If the callback is optional/conditional, default it: cb = cb || function(x) { return x; }.","Check for typos in the callback name and confirm it is defined before the reduce call."],"exampleFix":"// before\nvar total = items.reduce('sum', 0);\n\n// after\nvar total = items.reduce(function(acc, v) { return acc + v; }, 0);","handlingStrategy":"type-guard","validationCode":"if (typeof callback !== 'function') {\n  throw new Error('reduce callback must be a function, got ' + typeof callback);\n}","typeGuard":"function isFunction(v) { return typeof v === 'function'; }","tryCatchPattern":"if (e instanceof TypeError && /is not a function/.test(e.message)) {\n  reportUsageError('reduce', e); // point at the offending call site\n}","preventionTips":["Always pass a function literal or verified reference to reduce.","Default optional callbacks: cb = cb || identity.","Lint against passing strings/undefined where functions are expected."],"tags":["javascript","array","es5-shim","typeerror"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}