{"record":{"id":"cb9cfe03cc616248","repo":"angular/angular","slug":"arg-list-too-long","errorCode":null,"errorMessage":"Arg list too long.","messagePattern":"Arg list too long\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/zone.js/lib/common/utils.ts","lineNumber":348,"sourceCode":"    const a = bindArguments(<any>arguments, className);\n    switch (a.length) {\n      case 0:\n        this[originalInstanceKey] = new OriginalClass();\n        break;\n      case 1:\n        this[originalInstanceKey] = new OriginalClass(a[0]);\n        break;\n      case 2:\n        this[originalInstanceKey] = new OriginalClass(a[0], a[1]);\n        break;\n      case 3:\n        this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2]);\n        break;\n      case 4:\n        this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2], a[3]);\n        break;\n      default:\n        throw new Error('Arg list too long.');\n    }\n  };\n\n  // attach original delegate to patched function\n  attachOriginToPatched(_global[className], OriginalClass);\n\n  const instance = new OriginalClass(function () {});\n\n  let prop;\n  for (prop in instance) {\n    // https://bugs.webkit.org/show_bug.cgi?id=44721\n    if (className === 'XMLHttpRequest' && prop === 'responseBlob') continue;\n    (function (prop) {\n      if (typeof instance[prop] === 'function') {\n        _global[className].prototype[prop] = function () {\n          return this[originalInstanceKey][prop].apply(this[originalInstanceKey], arguments);\n        };\n      } else {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/zone.js/lib/common/utils.ts#L330-L366","documentation":"Thrown by zone.js patchClass's patched constructor wrapper (utils.ts:348). zone.js wraps browser classes (MutationObserver, IntersectionObserver, FileReader, WebKitMutationObserver) so instances are created inside the current zone, but the wrapper only forwards up to 4 constructor arguments; a 5th or later argument triggers this guard.","triggerScenarios":"Calling new MutationObserver(...)/FileReader()/IntersectionObserver(...) with 5 or more arguments — essentially always a bug in caller code (these APIs take 0-2 args), e.g. spreading an unbounded array into the constructor.","commonSituations":"Code doing new (window[someClass])(...args) with a dynamic args array that can exceed 4 elements; test harnesses passing extra config arguments to polyfilled observers.","solutions":["Pass only the arguments the Web API actually accepts (MutationObserver takes 1 callback, FileReader takes 0, IntersectionObserver at most 2).","If spreading an array, slice it to the documented arity: new MutationObserver(...args.slice(0, 1)).","Audit dynamic constructors invoked via window[className] patterns."],"exampleFix":"// before\nnew (window['MutationObserver'])(...collectedArgs); // collectedArgs.length may exceed 4\n\n// after\nnew MutationObserver(collectedArgs[0]); // pass exactly the documented callback","handlingStrategy":"validation","validationCode":"// Clamp dynamic constructor args to the API's real arity\nconst ARITY: Record<string, number> = {MutationObserver: 1, IntersectionObserver: 2, FileReader: 0};\nfunction constructObserver(name: keyof typeof ARITY, args: any[]) {\n  const Ctor = (window as any)[name];\n  return new Ctor(...args.slice(0, ARITY[name]));\n}","typeGuard":"function withinZonePatchLimit(args: unknown[]): boolean { return args.length <= 4; }","tryCatchPattern":"try { obs = new MutationObserver(...args); } catch (e: any) { if (/Arg list too long/.test(e.message)) { obs = new MutationObserver(args[0]); } else throw e; }","preventionTips":["Pass only documented constructor arguments to browser observer classes.","Avoid spreading unbounded arrays into constructors."],"tags":["zone-js","browser-api","mutationobserver","filereader"],"backgroundTag":"browser-api-constructor-arity-exceeded","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}