{"record":{"id":"700e3601693045b6","repo":"denoland/deno","slug":"invalid-name-must-not-be-infinity-or-nan","errorCode":null,"errorMessage":"invalid ${name}, must not be infinity or NaN","messagePattern":"invalid (.+?), must not be infinity or NaN","errorType":"validation","errorClass":"InvalidData","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/_fs_lutimes.ts","lineNumber":37,"sourceCode":"  PromisePrototypeThen,\n} = primordials;\n\ntype TimeLike = number | string | Date;\ntype PathLike = string | Buffer | URL;\n\nfunction getValidUnixTime(\n  value: TimeLike,\n  name: string,\n): [number, number] {\n  if (typeof value === \"string\") {\n    value = Number(value);\n  }\n\n  if (\n    typeof value === \"number\" &&\n    (NumberIsNaN(value) || !NumberIsFinite(value))\n  ) {\n    throw new Deno.errors.InvalidData(\n      `invalid ${name}, must not be infinity or NaN`,\n    );\n  }\n\n  const unixSeconds = toUnixTimestamp(value);\n\n  const seconds = MathTrunc(unixSeconds);\n  const nanoseconds = MathTrunc((unixSeconds * 1e3) - (seconds * 1e3)) * 1e6;\n\n  return [\n    seconds,\n    nanoseconds,\n  ];\n}\n\nexport function lutimes(\n  path: PathLike,\n  atime: TimeLike,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_fs/_fs_lutimes.ts#L19-L55","documentation":"fs.lutimes(path, atime, mtime, callback) converts each TimeLike (Date, number, or numeric string) into unix seconds/nanoseconds via getValidUnixTime. Strings are coerced with Number(), and if the resulting value is NaN or Infinity the polyfill throws Deno.errors.InvalidData with 'invalid atime/mtime, must not be infinity or NaN'. This guards the OS-level utimensat call, which cannot accept non-finite timestamps.","triggerScenarios":"fs.lutimes(path, 'not-a-date', new Date(), cb) — Number('not-a-date') is NaN; passing an already-invalid Date (new Date('garbage')) whose getTime() is NaN; passing Infinity from a computation like 1/0 or Number.MAX_VALUE * 2; an empty string atime ('' coerces to 0 and passes, but 'abc' fails).","commonSituations":"Parsing timestamps from filenames or metadata that may not be numeric; feeding client-supplied strings straight into utimes-style APIs; DST/parse edge cases producing Invalid Date objects.","solutions":["Validate before calling: Number.isFinite(new Date(atime).getTime())","Sanitize strings with a fallback: Number.isNaN(Number(s)) ? Date.now() : s","If the value may be absent, pass a fresh Date or omit the lutimes call instead of sending NaN"],"exampleFix":"// before\nfs.lutimes(path, 'yesterday-ish', mtime, cb); // Number('yesterday-ish') = NaN\n\n// after\nconst atime = new Date('2024-01-01T00:00:00Z');\nif (Number.isFinite(atime.getTime())) {\n  fs.lutimes(path, atime.getTime() / 1000, mtime, cb);\n}","handlingStrategy":"validation","validationCode":"const toTime = (v) => typeof v === 'string' ? Number(v) : (v instanceof Date ? v.getTime() / 1000 : v);\nif (!Number.isFinite(toTime(atime)) || !Number.isFinite(toTime(mtime))) throw new RangeError('atime/mtime must be finite');","typeGuard":"const isValidTimeLike = (v) => { const n = typeof v === 'string' ? Number(v) : (v instanceof Date ? v.getTime() / 1000 : v); return typeof n === 'number' && Number.isFinite(n); };","tryCatchPattern":"try { fs.lutimesSync(p, atime, mtime); } catch (e) { if (e instanceof Deno.errors.InvalidData) { /* coerce to a sane default and retry once with Date.now() */ } else throw e; }","preventionTips":["Never pass unvalidated user strings as timestamps","Check Number.isFinite(Date.parse-like values) before utimes-family calls","Invalid Date objects (new Date(badString)) have NaN getTime() — validate the Date itself"],"tags":["node-compat","fs","lutimes","timestamp","nan","infinity","validation","deno"],"backgroundTag":"invalid-file-timestamp","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}