{"record":{"id":"7f8f1a0ed6a1265c","repo":"denoland/deno","slug":"err-invalid-arg-value-7f8f1a","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'tracked' is not a tracked function. Received ${inspected}","messagePattern":"The argument 'tracked' is not a tracked function\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/assert/calltracker.js","lineNumber":87,"sourceCode":"        `executed ${this.#calls.length} time(s).`;\n      return {\n        message,\n        actual: this.#calls.length,\n        expected: this.#expected,\n        operator: this.#name,\n        stack: this.#stackTrace,\n      };\n    }\n  }\n}\n\nclass CallTracker {\n  #callChecks = new SafeSet();\n  #trackedFunctions = new SafeWeakMap();\n\n  #getTrackedFunction(tracked) {\n    if (!this.#trackedFunctions.has(tracked)) {\n      throw new ERR_INVALID_ARG_VALUE(\n        \"tracked\",\n        tracked,\n        \"is not a tracked function\",\n      );\n    }\n    return this.#trackedFunctions.get(tracked);\n  }\n\n  reset(tracked) {\n    if (tracked === undefined) {\n      SetPrototypeForEach(this.#callChecks, (check) => check.reset());\n      return;\n    }\n\n    this.#getTrackedFunction(tracked).reset();\n  }\n\n  getCalls(tracked) {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/assert/calltracker.js#L69-L105","documentation":"CallTracker wraps each function passed to tracker.calls(fn, expected) in a tracking context stored in an internal WeakMap. reset(tracked) and getCalls(tracked) look the argument up in that map; an argument that was never registered — most commonly the original fn instead of the wrapper calls() returns — throws ERR_INVALID_ARG_VALUE with 'is not a tracked function'.","triggerScenarios":"tracker.getCalls(fn) or tracker.reset(fn) where fn was never wrapped — e.g. const wrapped = tracker.calls(fn); tracker.getCalls(fn); (original fn passed instead of the wrapper). Passing a function registered on a different CallTracker instance, or the pre-wrap reference kept alive by a refactor, produces the same throw.","commonSituations":"Refactors that keep a reference to the pre-wrap function; passing a function wrapped by a different tracker instance; asserting on the wrong export of a module.","solutions":["Always keep the return value of tracker.calls(fn) and pass that wrapper to getCalls()/reset().","Reassign in place — fn = tracker.calls(fn) — so every later reference is the tracked one.","Consider node:test's mock module (mock.fn / mock.method) — CallTracker is deprecated in modern Node."],"exampleFix":"// before\ntracker.calls(handleRequest);   // wrapper discarded\nhandleRequest(req, res);         // calls original: nothing recorded\ntracker.getCalls(handleRequest); // ERR_INVALID_ARG_VALUE: not a tracked function\n\n// after\nconst handleTracked = tracker.calls(handleRequest);\nhandleTracked(req, res);\ntracker.getCalls(handleTracked);  // recorded call arguments","handlingStrategy":"validation","validationCode":"const trackedFns = new WeakSet();\nfunction track(tracker, fn, expected = 1) {\n  const wrapped = tracker.calls(fn, expected);\n  trackedFns.add(wrapped);\n  return wrapped;\n}\nfunction isTracked(fn) {\n  return trackedFns.has(fn);\n}\n// before tracker.getCalls(x): if (!isTracked(x)) throw new Error('untracked fn');","typeGuard":null,"tryCatchPattern":"try {\n  tracker.getCalls(fn);\n} catch (e) {\n  if (e.code === 'ERR_INVALID_ARG_VALUE' && /tracked function/.test(e.message)) {\n    // re-wrap fn with tracker.calls and use the returned wrapper\n  } else throw e;\n}","preventionTips":["Treat tracker.calls() as returning the new handle — always store and use it.","Reassign in place (fn = tracker.calls(fn)) so all call sites use the wrapper.","Prefer node:test mock.fn()/mock.method() over the deprecated CallTracker."],"tags":["testing","assert","calltracker","node-compat"],"backgroundTag":"calltracker-untracked-function","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}