{"record":{"id":"92740ebe5e02cb5a","repo":"denoland/deno","slug":"err-invalid-arg-type-92740e","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"promiseFn\" argument must be an instance of Function or Promise. Received ${promiseFn}","messagePattern":"The \"promiseFn\" argument must be an instance of Function or Promise\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":362,"sourceCode":"async function waitForActual(\n  promiseFn,\n) {\n  let resultPromise;\n  if (typeof promiseFn === \"function\") {\n    // Return a rejected promise if `promiseFn` throws synchronously.\n    resultPromise = promiseFn();\n    // Fail in case no promise is returned.\n    if (!checkIsPromise(resultPromise)) {\n      throw new ERR_INVALID_RETURN_VALUE(\n        \"instance of Promise\",\n        \"promiseFn\",\n        resultPromise,\n      );\n    }\n  } else if (checkIsPromise(promiseFn)) {\n    resultPromise = promiseFn;\n  } else {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"promiseFn\",\n      [\"Function\", \"Promise\"],\n      promiseFn,\n    );\n  }\n\n  try {\n    await resultPromise;\n  } catch (e) {\n    return e;\n  }\n  return NO_EXCEPTION_SENTINEL;\n}\n\nfunction expectsError(\n  stackStartFn,\n  actual,\n  error,","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/assert.ts#L344-L380","documentation":"Thrown by assert.rejects()/assert.doesNotReject() when the first argument is neither a function nor a Promise. waitForActual() accepts only those two shapes; anything else (number, string, plain object without a thenable interface, undefined) is rejected immediately with ERR_INVALID_ARG_TYPE.","triggerScenarios":"assert.rejects(123); assert.doesNotReject('ready'); assert.rejects({ then: 'not a function' }); passing a variable that is undefined at runtime.","commonSituations":"Passing a computed value or flag instead of the operation to await; a variable expected to hold a promise but undefined after a refactor; copy-pasting assert(value) style calls into assert.rejects().","solutions":["Pass a Promise: assert.rejects(promise)","Pass a function that returns the Promise: assert.rejects(() => promise)","If the variable may be undefined, check it before the call and fail early"],"exampleFix":"// before\nassert.rejects(maybePromise);\n// after\nassert.rejects(Promise.resolve(maybePromise));","handlingStrategy":"type-guard","validationCode":"if (!isFnOrPromise(target)) throw new TypeError('assert.rejects expects a function or a Promise');\nawait assert.rejects(target, /boom/);","typeGuard":"const isFnOrPromise = (v) => typeof v === 'function' || (v != null && typeof v.then === 'function');","tryCatchPattern":null,"preventionTips":["Treat the first argument of rejects/doesNotReject as operation-to-await, never as data","Fail fast when the variable holding the promise is undefined"],"tags":["assert","testing","async","validation","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}