denoland/deno · error · Deno.errors.InvalidData
invalid ${name}, must not be infinity or NaN
Error message
invalid ${name}, must not be infinity or NaN What it means
getValidUnixTime (ext/node/polyfills/_fs/_fs_lutimes.ts) converts each atime/mtime of fs.lutimes/fs.lutimesSync to [seconds, nanoseconds]. Strings are coerced with Number(value); if the result is NaN or Infinity, it throws Deno.errors.InvalidData with 'invalid ${name}, must not be infinity or NaN' where name is 'atime' or 'mtime'. lutimes changes timestamps of a symlink itself, so both time arguments must be finite.
Source
Thrown at ext/node/polyfills/_fs/_fs_lutimes.ts:37
PromisePrototypeThen,
} = primordials;
type TimeLike = number | string | Date;
type PathLike = string | Buffer | URL;
function getValidUnixTime(
value: TimeLike,
name: string,
): [number, number] {
if (typeof value === "string") {
value = Number(value);
}
if (
typeof value === "number" &&
(NumberIsNaN(value) || !NumberIsFinite(value))
) {
throw new Deno.errors.InvalidData(
`invalid ${name}, must not be infinity or NaN`,
);
}
const unixSeconds = toUnixTimestamp(value);
const seconds = MathTrunc(unixSeconds);
const nanoseconds = MathTrunc((unixSeconds * 1e3) - (seconds * 1e3)) * 1e6;
return [
seconds,
nanoseconds,
];
}
export function lutimes(
path: PathLike,
atime: TimeLike,View on GitHub (pinned to 89f33cbef2)
Solutions
- Pass Date objects or numeric seconds/ms directly instead of strings
- Sanitize inputs: coerce and check Number.isFinite before calling lutimes
- If the value comes from user input, reject it early with your own validation message
Example fix
// before
await fs.promises.lutimes(link, cfg.atime, Date.now()); // cfg.atime = '' -> NaN
// after
const at = Number(cfg.atime);
if (!Number.isFinite(at)) throw new TypeError('cfg.atime must be a finite number');
await fs.promises.lutimes(link, at, Date.now()); Defensive patterns
Strategy: validation
Validate before calling
const toFiniteUnix = (v) => {
const n = typeof v === 'string' ? Number(v) : v;
if (typeof n !== 'number' || !Number.isFinite(n)) {
throw new TypeError(`time must be finite, got ${String(v)}`);
}
return n;
}; Type guard
function isValidTimeLike(v) {
if (typeof v === 'string') return Number.isFinite(Number(v));
return typeof v === 'number' || v instanceof Date;
} Try / catch
try { await fsp.lutimes(p, at, mt); } catch (e) { if (e instanceof Deno.errors.InvalidData) { /* fix time source */ } else throw e; } Prevention
- Pass Date objects instead of string timestamps
- Validate config-sourced numbers with Number.isFinite before use
- Remember strings are coerced with Number(), not Date.parse — '2024-01-01' is not valid here
When it happens
Trigger: fs.lutimes(link, 'not-a-date', new Date(), cb) (Number('not-a-date') is NaN); fs.lutimes(link, Infinity, 0, cb); passing an empty string or unparsable numeric string as atime/mtime.
Common situations: Reading timestamps from config or CLI args that may be empty/unparsable; computing mtime as a division that yields Infinity (e.g., 1/0); passing Date objects serialized as strings that are not numeric.
Related errors
- A file exists at the destination: ${destStr}
- ERR_MISSING_ARGS
- No callback function supplied
- ERR_INVALID_ARG_TYPE
- No callback function supplied
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/700e3601693045b6.
Report an issue: GitHub.