Promise rejected with a falsy value
Production Risk
Low — causes confusing error wrapping; always use Error objects for rejections.
Thrown when a Promise is rejected with a falsy value (null, undefined, 0, false, or empty string) and that rejection is converted to an error by Node.js utilities such as util.callbackify(). Since Node.js error conventions require Errors as rejection reasons, falsy rejections must be wrapped.
- 1Calling reject(null) or reject(undefined) in a Promise constructor
- 2A function returning a rejected Promise with a non-Error value
- 3Using util.callbackify() on a function that rejects with falsy values
Triggered by util.callbackify() when the promisified function rejects with a falsy value.
const { callbackify } = require('util');
async function badFn() { throw null; } // falsy rejection
const cbFn = callbackify(badFn);
cbFn((err) => {
console.error(err.code); // ERR_FALSY_VALUE_REJECTION
console.error(err.reason); // null
});expected output
Error [ERR_FALSY_VALUE_REJECTION]: Promise was rejected with falsy value
Fix 1
Always reject Promises with Error instances
WHEN When creating or returning rejected Promises
async function goodFn() {
throw new Error('Something went wrong'); // proper Error
}Why this works
Rejecting with an Error instance satisfies util.callbackify() and all Node.js error conventions.
Fix 2
Handle the wrapped error in callbackify callbacks
WHEN When working with third-party code that may reject with falsy values
cbFn((err) => {
if (err && err.code === 'ERR_FALSY_VALUE_REJECTION') {
console.warn('Received falsy rejection:', err.reason);
return;
}
if (err) throw err;
});Why this works
Checking for ERR_FALSY_VALUE_REJECTION lets you handle the wrapped error appropriately.
const { callbackify } = require('util');
async function badFn() { throw null; } // falsy rejection
const cbFn = callbackify(badFn);
cbFn((err) => {
console.error(err.code); // ERR_FALSY_VALUE_REJECTION
console.error(err.reason); // null // this triggers ERR_FALSY_VALUE_REJECTIONtry {
// operation that may throw ERR_FALSY_VALUE_REJECTION
riskyOperation()
} catch (err) {
if (err.code === 'ERR_FALSY_VALUE_REJECTION') {
console.error('ERR_FALSY_VALUE_REJECTION:', err.message)
} else {
throw err
}
}// Validate inputs before calling the operation
function safe_err_falsy_value_rejection(...args) {
// validate args here
return performOperation(...args)
}✕ Reject Promises with null, undefined, or other falsy values
Falsy rejections break error-handling conventions and require special handling in callbackify.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev