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

  1. Pass a callback: fs.ftruncate(fd, 10, (err) => ...)
  2. Use the promise API: await fs.promises.ftruncate(fd, 10)
  3. 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

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


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/e719aebf437875e0. Report an issue: GitHub.