{"record":{"id":"481ccefa7efcf04b","repo":"denoland/deno","slug":"err-invalid-arg-value-481cce","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'x' is invalid. Received ${x}","messagePattern":"The argument 'x' is invalid\\. Received (.+?)","errorType":"validation","errorClass":"ERR_INVALID_ARG_VALUE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/readline/callbacks.mjs","lineNumber":64,"sourceCode":"  kClearToLineBeginning,\n  kClearToLineEnd,\n} = CSI;\n\n/**\n * moves the cursor to the x and y coordinate on the given stream\n */\n\nfunction cursorTo(stream, x, y, callback) {\n  if (callback !== undefined) {\n    validateFunction(callback, \"callback\");\n  }\n\n  if (typeof y === \"function\") {\n    callback = y;\n    y = undefined;\n  }\n\n  if (NumberIsNaN(x)) throw new ERR_INVALID_ARG_VALUE(\"x\", x);\n  if (NumberIsNaN(y)) throw new ERR_INVALID_ARG_VALUE(\"y\", y);\n\n  if (stream == null || (typeof x !== \"number\" && typeof y !== \"number\")) {\n    if (typeof callback === \"function\") process.nextTick(callback, null);\n    return true;\n  }\n\n  if (typeof x !== \"number\") throw new ERR_INVALID_CURSOR_POS();\n\n  const data = typeof y !== \"number\" ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`;\n  return stream.write(data, callback);\n}\n\n/**\n * moves the cursor relative to its current location\n */\n\nfunction moveCursor(stream, dx, dy, callback) {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/readline/callbacks.mjs#L46-L82","documentation":"readline.cursorTo validates its x coordinate: if x is NaN it throws ERR_INVALID_ARG_VALUE immediately, before the stream checks. x is a 0-based column for the ANSI cursor sequence, so NaN (not undefined — non-numbers take an early no-op path) can only come from arithmetic or explicit NaN.","triggerScenarios":"readline.cursorTo(process.stdout, NaN); x computed as width - something where width is undefined (undefined - 1 = NaN); passing parseFloat(userInput) when the input is not numeric.","commonSituations":"Terminal UI/progress renderers computing columns from terminal width that is unavailable (output redirected, not a TTY); parseFloat of empty string; division by zero in layout math.","solutions":["Check Number.isFinite(x) before calling cursorTo and skip rendering when not","Default the column: const col = Number.isFinite(x) ? x : 0","Fix the upstream width source (process.stdout.columns ?? 80) that produced NaN"],"exampleFix":"// before\nreadline.cursorTo(stream, pos.col - 1); // pos.col undefined -> NaN\n\n// after\nreadline.cursorTo(stream, (pos.col ?? 1) - 1);","handlingStrategy":"validation","validationCode":"function cursorCol(stream: NodeJS.WriteStream, x: number) {\n  if (Number.isFinite(x)) readline.cursorTo(stream, x);\n}","typeGuard":"const isFiniteCoord = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":"try {\n  readline.cursorTo(stream, x);\n} catch (err) {\n  if (err?.code === 'ERR_INVALID_ARG_VALUE' && /x/.test(err.message)) {\n    readline.cursorTo(stream, 0);\n  } else throw err;\n}","preventionTips":["Fallback terminal width: process.stdout.columns ?? 80, so column math never sees undefined","Check Number.isFinite on values from parseFloat/env before any cursor call"],"tags":["readline","tty","node-compat","deno","cursor"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-26T04:18:47.238Z"}