{"record":{"id":"bab939eafb329a3a","repo":"denoland/deno","slug":"err-invalid-return-value-bab939","errorCode":"ERR_INVALID_RETURN_VALUE","errorMessage":"Expected instance of Promise to be returned from the \"promiseFn\" function but got ${determineSpecificType(resultPromise)}.","messagePattern":"Expected instance of Promise to be returned from the \"promiseFn\" function but got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":353,"sourceCode":"  // Accept native ES6 promises and promises that are implemented in a similar\n  // way. Do not accept thenables that use a function as `obj` and that have no\n  // `catch` handler.\n  return isPromise(obj) ||\n    (obj !== null && typeof obj === \"object\" &&\n      typeof obj.then === \"function\" &&\n      typeof obj.catch === \"function\");\n}\n\nasync 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) {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/assert.ts#L335-L371","documentation":"assert.rejects/assert.doesNotReject accept either a Promise or a function that must return one. waitForActual invokes the function and runs checkIsPromise on the result; if the return value lacks then/catch (not a thenable), it throws ERR_INVALID_RETURN_VALUE ('Expected instance of Promise to be returned from the \"promiseFn\" function') before anything is awaited. This mirrors Node.js's identical check in lib/assert.js.","triggerScenarios":"assert.rejects(() => 42), assert.rejects(() => null), assert.rejects(() => { compute(); }) with a forgotten return, or a factory that conditionally returns a promise on some paths and undefined on others. The function is called exactly once and its return value is inspected immediately.","commonSituations":"Refactoring an async helper into a sync one and forgetting to update the test; passing a mapper/callback-style function instead of an async factory; omitting the async keyword on the arrow function so it returns the raw value; conditional returns where only the happy path returns the promise.","solutions":["Make the factory async so every path yields a promise: assert.rejects(async () => { ... }, expected).","Or pass the promise directly instead of a factory: assert.rejects(fetch(url), expected).","Audit the factory for branches that return without a value (implicit undefined) and return the promise from all paths.","Keep the assertion and the async contract in sync when renaming or wrapping helpers."],"exampleFix":"// before\nassert.rejects(() => getUser(-1), { name: 'RangeError' }); // getUser is async, wrapper returns undefined\n\n// after\nassert.rejects(async () => getUser(-1), { name: 'RangeError' });","handlingStrategy":"type-guard","validationCode":"const factory = () => getUser(-1);\nconst probe = factory();\nif (!(probe instanceof Promise)) {\n  // fix the factory: make it async or return the promise directly\n  assert.rejects(async () => getUser(-1), expected);\n} else {\n  assert.rejects(probe, expected);\n}","typeGuard":"const returnsPromise = (fn) => {\n  try { return fn() instanceof Promise; } catch { return false; }\n};","tryCatchPattern":"try {\n  await assert.rejects(factory, expected);\n} catch (e) {\n  if (e.code === 'ERR_INVALID_RETURN_VALUE') {\n    throw new Error('assert.rejects factory must return a Promise — make it async');\n  }\n  throw e;\n}","preventionTips":["Default to async factories: assert.rejects(async () => ...).","Or pass the promise itself: assert.rejects(doWork(), expected).","Ensure every branch of the factory returns the promise — no implicit undefined returns."],"tags":["assert","assert-rejects","promise","invalid-return-value","node-compat","deno"],"backgroundTag":"function-did-not-return-promise","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}