{"record":{"id":"6f2e1a2b34a16e4b","repo":"dianping/cat","slug":"can-t-convert-o-to-object","errorCode":null,"errorMessage":"can't convert {o} to object","messagePattern":"can't convert (.+?) to object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":49531,"sourceCode":"    valueOf = input.valueOf;\n    if (typeof valueOf === \"function\") {\n        val = valueOf.call(input);\n        if (isPrimitive(val)) {\n            return val;\n        }\n    }\n    toString = input.toString;\n    if (typeof toString === \"function\") {\n        val = toString.call(input);\n        if (isPrimitive(val)) {\n            return val;\n        }\n    }\n    throw new TypeError();\n}\nvar toObject = function (o) {\n    if (o == null) { // this matches both null and undefined\n        throw new TypeError(\"can't convert \"+o+\" to object\");\n    }\n    return Object(o);\n};\n\n});\n","sourceCodeStart":49513,"sourceCodeEnd":49537,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L49513-L49537","documentation":"An internal toObject helper in the bundled es5-shim: it coerces an argument to an object and throws this TypeError when the value is null or undefined, since Object(null) itself would not throw but the operation calling toObject (e.g. Function.prototype.apply/bind argument processing) requires an actual object. The message embeds the value ('null' or 'undefined' as text).","triggerScenarios":"Passing null/undefined where the shim internally calls toObject — most commonly Function.prototype.apply(null-ish thisArg lists) polyfills, or Array.prototype slice/concat-style helpers invoked on null. Also hit when caller code does Array.prototype.forEach.call(null, fn) under the shim.","commonSituations":"Calling array generics on a possibly-null collection; a callback receiving undefined because an event or XHR delivered no payload; refactoring that left a variable uninitialized in one branch.","solutions":["Guard before the call: if (list == null) list = [];","Fix the upstream source of null/undefined (the missing payload or uninitialized variable).","Prefer Array.from/list.slice patterns on values you have already defaulted."],"exampleFix":"// before\nArray.prototype.forEach.call(items, render); // items may be undefined\n\n// after\n(items || []).forEach(render);","handlingStrategy":"validation","validationCode":"if (list == null) list = []; // or throw a contextual error naming the missing field","typeGuard":"function isNonNullObject(v) {\n  return v !== null && v !== undefined && typeof v === 'object';\n}","tryCatchPattern":null,"preventionTips":["Default collections: (items || []).forEach(...)","Validate payloads from events/XHR before passing to array generics","Initialize arrays in every branch of construction logic"],"tags":["es5-shim","null-safety","polyfill","typeerror"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}