denoland/deno · error · TypeError
ERR_INVALID_ARG_TYPE
ERR_INVALID_ARG_TYPE
Error message
The "promiseFn" argument must be an instance of Function or Promise. Received ${promiseFn} What it means
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.
Source
Thrown at ext/node/polyfills/assert.ts:362
async function waitForActual(
promiseFn,
) {
let resultPromise;
if (typeof promiseFn === "function") {
// Return a rejected promise if `promiseFn` throws synchronously.
resultPromise = promiseFn();
// Fail in case no promise is returned.
if (!checkIsPromise(resultPromise)) {
throw new ERR_INVALID_RETURN_VALUE(
"instance of Promise",
"promiseFn",
resultPromise,
);
}
} else if (checkIsPromise(promiseFn)) {
resultPromise = promiseFn;
} else {
throw new ERR_INVALID_ARG_TYPE(
"promiseFn",
["Function", "Promise"],
promiseFn,
);
}
try {
await resultPromise;
} catch (e) {
return e;
}
return NO_EXCEPTION_SENTINEL;
}
function expectsError(
stackStartFn,
actual,
error,View on GitHub (pinned to 89f33cbef2)
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
Example fix
// before assert.rejects(maybePromise); // after assert.rejects(Promise.resolve(maybePromise));
Defensive patterns
Strategy: type-guard
Validate before calling
if (!isFnOrPromise(target)) throw new TypeError('assert.rejects expects a function or a Promise');
await assert.rejects(target, /boom/); Type guard
const isFnOrPromise = (v) => typeof v === 'function' || (v != null && typeof v.then === 'function');
Prevention
- Treat the first argument of rejects/doesNotReject as operation-to-await, never as data
- Fail fast when the variable holding the promise is undefined
When it happens
Trigger: assert.rejects(123); assert.doesNotReject('ready'); assert.rejects({ then: 'not a function' }); passing a variable that is undefined at runtime.
Common situations: 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().
Related errors
- ERR_INVALID_ARG_VALUE
- ERR_INVALID_RETURN_VALUE
- ERR_CONSTRUCT_CALL_REQUIRED
- ERR_ASSERTION
- ERR_AMBIGUOUS_ARGUMENT
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/92740ebe5e02cb5a.
Report an issue: GitHub.