denoland/deno · error · Error
No callback function supplied
Error message
No callback function supplied
What it means
fs.ftruncate falls back to a plain Error with 'No callback function supplied' when neither the second nor third argument is a function — i.e. the caller used the callback API without a callback. The polyfill checks this after fd/len validation but before starting the truncate, so nothing is executed.
Source
Thrown at ext/node/polyfills/fs.ts:1471
maybeCallback?: CallbackWithError,
) {
let len: number = 0;
let callback: CallbackWithError | undefined;
if (typeof lenOrCallback === "function") {
callback = lenOrCallback;
} else {
len = lenOrCallback;
callback = maybeCallback;
}
// Match Node: validate fd and len before any async work (lib/fs.js).
if (typeof fd !== "number") {
throw new ERR_INVALID_ARG_TYPE("fd", "number", fd);
}
validateInteger(len, "len");
len = MathMax(0, len);
if (!callback) throw new Error("No callback function supplied");
PromisePrototypeThen(
op_node_fs_ftruncate(fd, len),
() => callback(null),
callback,
);
}
function ftruncateSync(fd: number, len: number = 0) {
if (typeof fd !== "number") {
throw new ERR_INVALID_ARG_TYPE("fd", "number", fd);
}
validateInteger(len, "len");
op_node_fs_ftruncate_sync(fd, MathMax(0, len));
}
function _getValidTime(
time: number | string | Date,View on GitHub (pinned to 89f33cbef2)
Solutions
- Pass a callback: fs.ftruncate(fd, 10, (err) => ...)
- Use the promise API: await fs.promises.ftruncate(fd, 10)
- Use fs.ftruncateSync(fd, 10) in synchronous code
Example fix
// before fs.ftruncate(fd, 10); // no callback // after await fs.promises.ftruncate(fd, 10);
Defensive patterns
Strategy: validation
Validate before calling
if (typeof cb !== 'function') {
throw new TypeError('fs.ftruncate requires a callback');
}
fs.ftruncate(fd, len, cb); Type guard
const isCallback = (v: unknown): v is () => void => typeof v === 'function';
Prevention
- Standardize a single API style per module (promises or callbacks) to avoid half-migrated calls
- Enable TypeScript checks so a missing callback fails at compile time
- Wrap callback APIs once in a promise helper instead of calling them ad hoc
When it happens
Trigger: fs.ftruncate(fd); fs.ftruncate(fd, 10); — any call shape where no function appears in the lenOrCallback or maybeCallback positions.
Common situations: Migrating code from fsPromises.ftruncate (returns a promise, no callback) to the callback API; copy-paste that drops the trailing callback; calling the callback variant from code that expects a return value.
Related errors
- No callback function supplied
- ERR_INVALID_ARG_TYPE
- invalid ${name}, must not be infinity or NaN
- resolve hook must return { shortCircuit: true } or call next
- load hook must return { shortCircuit: true } or call nextLoa
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/e719aebf437875e0.
Report an issue: GitHub.