{"record":{"id":"e719aebf437875e0","repo":"denoland/deno","slug":"no-callback-function-supplied-e719ae","errorCode":null,"errorMessage":"No callback function supplied","messagePattern":"No callback function supplied","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/fs.ts","lineNumber":1471,"sourceCode":"  maybeCallback?: CallbackWithError,\n) {\n  let len: number = 0;\n  let callback: CallbackWithError | undefined;\n  if (typeof lenOrCallback === \"function\") {\n    callback = lenOrCallback;\n  } else {\n    len = lenOrCallback;\n    callback = maybeCallback;\n  }\n\n  // Match Node: validate fd and len before any async work (lib/fs.js).\n  if (typeof fd !== \"number\") {\n    throw new ERR_INVALID_ARG_TYPE(\"fd\", \"number\", fd);\n  }\n  validateInteger(len, \"len\");\n  len = MathMax(0, len);\n\n  if (!callback) throw new Error(\"No callback function supplied\");\n\n  PromisePrototypeThen(\n    op_node_fs_ftruncate(fd, len),\n    () => callback(null),\n    callback,\n  );\n}\n\nfunction ftruncateSync(fd: number, len: number = 0) {\n  if (typeof fd !== \"number\") {\n    throw new ERR_INVALID_ARG_TYPE(\"fd\", \"number\", fd);\n  }\n  validateInteger(len, \"len\");\n  op_node_fs_ftruncate_sync(fd, MathMax(0, len));\n}\n\nfunction _getValidTime(\n  time: number | string | Date,","sourceCodeStart":1453,"sourceCodeEnd":1489,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/fs.ts#L1453-L1489","documentation":"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.","triggerScenarios":"fs.ftruncate(fd); fs.ftruncate(fd, 10); — any call shape where no function appears in the lenOrCallback or maybeCallback positions.","commonSituations":"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.","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"],"exampleFix":"// before\nfs.ftruncate(fd, 10); // no callback\n\n// after\nawait fs.promises.ftruncate(fd, 10);","handlingStrategy":"validation","validationCode":"if (typeof cb !== 'function') {\n  throw new TypeError('fs.ftruncate requires a callback');\n}\nfs.ftruncate(fd, len, cb);","typeGuard":"const isCallback = (v: unknown): v is () => void => typeof v === 'function';","tryCatchPattern":null,"preventionTips":["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"],"tags":["node-compat","filesystem","callback","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}