{"record":{"id":"928b211e33124cc2","repo":"denoland/deno","slug":"invalid-name-must-not-be-infinity-or-nan-928b21","errorCode":null,"errorMessage":"invalid ${name}, must not be infinity or NaN","messagePattern":"invalid (.+?), must not be infinity or NaN","errorType":"validation","errorClass":"Deno.errors.InvalidData","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/fs.ts","lineNumber":1500,"sourceCode":"    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,\n  name: string,\n): number | Date {\n  if (typeof time === \"string\") {\n    time = Number(time);\n  }\n\n  if (\n    typeof time === \"number\" &&\n    (NumberIsNaN(time) || !NumberIsFinite(time))\n  ) {\n    throw new Deno.errors.InvalidData(\n      `invalid ${name}, must not be infinity or NaN`,\n    );\n  }\n\n  return toUnixTimestamp(time);\n}\n\nfunction futimes(\n  fd: number,\n  atime: number | string | Date,\n  mtime: number | string | Date,\n  callback: CallbackWithError,\n) {\n  if (!callback) {\n    throw new Deno.errors.InvalidData(\"No callback function supplied\");\n  }\n  if (typeof fd !== \"number\") {\n    throw new ERR_INVALID_ARG_TYPE(\"fd\", \"number\", fd);","sourceCodeStart":1482,"sourceCodeEnd":1518,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/fs.ts#L1482-L1518","documentation":"futimes and futimesSync normalize atime/mtime through _getValidTime: strings are converted with Number(), and if the resulting number is NaN or non-finite the function throws Deno.errors.InvalidData. This guards the OS-level utimensat call against timestamps it cannot represent.","triggerScenarios":"fs.futimes(fd, 'not-a-date', new Date(), cb) (Number('not-a-date') is NaN); passing Infinity or NaN directly; a numeric string like 'abc' sourced from config or CLI flags.","commonSituations":"Touch-like scripts taking timestamps from user input; empty-string defaults that become NaN; values parsed from headers or query strings without validation.","solutions":["Pass Date objects or finite numbers (epoch seconds) instead of free-form strings","Validate with Number.isFinite(Number(v)) before the call when input is external","Default missing timestamps to a known value such as Date.now() / 1000"],"exampleFix":"// before\nfs.futimes(fd, ts, mtime, cb); // ts = 'abc' from argv -> NaN\n\n// after\nconst t = Number(ts);\nfs.futimes(fd, Number.isFinite(t) ? t : Date.now() / 1000, mtime, cb);","handlingStrategy":"validation","validationCode":"const toTime = (v: number | string | Date): number => {\n  const n = typeof v === 'string' ? Number(v) : (v as number);\n  if (!Number.isFinite(n)) throw new RangeError('invalid time');\n  return n;\n};\ntoTime(atime); toTime(mtime); // before fs.futimes","typeGuard":"const isValidTime = (v: unknown): v is number | Date =>\n  typeof v === 'number' ? Number.isFinite(v)\n    : typeof v === 'string' ? Number.isFinite(Number(v))\n    : v instanceof Date && !isNaN(v.getTime());","tryCatchPattern":"try {\n  await fs.promises.futimes(fd, atime, mtime);\n} catch (err) {\n  if (err instanceof Deno.errors.InvalidData) { /* bad timestamp input: fix source */ }\n  throw err;\n}","preventionTips":["Pass Date objects or epoch numbers; avoid free-form string timestamps","Validate user/config-sourced times with Number.isFinite(Number(v)) first","Note invalid Date objects can also yield NaN downstream — check isNaN(date.getTime())"],"tags":["node-compat","filesystem","validation","timestamp"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}