{"record":{"id":"f30148f281ff96d2","repo":"denoland/deno","slug":"err-invalid-arg-value-f30148","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The property 'prevValue.user' is invalid","messagePattern":"The property 'prevValue\\.user' is invalid","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/process.ts","lineNumber":290,"sourceCode":"  user: number;\n  system: number;\n}\n\n// Ensure that a previously passed in value is valid. Currently, the native\n// implementation always returns numbers <= Number.MAX_SAFE_INTEGER.\nfunction previousCpuUsageValueIsValid(num) {\n  return typeof num === \"number\" && num >= 0 && num <= NumberMAX_SAFE_INTEGER;\n}\n\nexport function cpuUsage(previousValue?: CpuUsage): CpuUsage {\n  const cpuValues = Deno.cpuUsage(previousValue);\n\n  if (previousValue) {\n    if (!previousCpuUsageValueIsValid(previousValue.user)) {\n      validateObject(previousValue, \"prevValue\");\n\n      validateNumber(previousValue.user, \"prevValue.user\");\n      throw new ERR_INVALID_ARG_VALUE_RANGE(\n        \"prevValue.user\",\n        previousValue.user,\n      );\n    }\n\n    if (!previousCpuUsageValueIsValid(previousValue.system)) {\n      validateNumber(previousValue.system, \"prevValue.system\");\n      throw new ERR_INVALID_ARG_VALUE_RANGE(\n        \"prevValue.system\",\n        previousValue.system,\n      );\n    }\n\n    return {\n      user: cpuValues.user - previousValue.user,\n      system: cpuValues.system - previousValue.system,\n    };\n  }","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/process.ts#L272-L308","documentation":"process.cpuUsage(previousValue) requires previousValue.user (and .system) to be numbers in [0, Number.MAX_SAFE_INTEGER]. When user is a number but negative, NaN, Infinity, or above the safe range, validation passes the type check (validateNumber) and then throws ERR_INVALID_ARG_VALUE. Non-number values throw a different ERR_INVALID_ARG_TYPE error instead.","triggerScenarios":"process.cpuUsage({ user: -1, system: 0 }); { user: NaN } from a bad computation; { user: Infinity } from dividing by zero; feeding a hand-constructed or mutated baseline object instead of a genuine snapshot.","commonSituations":"Re-feeding a previously computed diff (which can be 0/negative after rounding) as the new baseline; serializing snapshots through float32/JSON losing precision past MAX_SAFE_INTEGER; copying only some fields off a real snapshot.","solutions":["Only pass the verbatim object returned by a previous process.cpuUsage() call","Keep raw snapshots, not computed diffs, as baselines: const start = process.cpuUsage(); ... process.cpuUsage(start)","If baselines come from storage, validate/reject them instead of calling the API: both fields must be finite numbers >= 0","threadCpuUsage has the same constraint — apply the same rule there"],"exampleFix":"// before\nconst delta = process.cpuUsage(start);\nprocess.cpuUsage(delta); // diff-of-diff, may be invalid\n\n// after\nconst start = process.cpuUsage();\n// ... work ...\nconst delta = process.cpuUsage(start); // always pass a raw snapshot","handlingStrategy":"validation","validationCode":"function isCpuUsageSnapshot(v) {\n  return typeof v === \"object\" && v !== null &&\n    Number.isFinite(v.user) && v.user >= 0 && v.user <= Number.MAX_SAFE_INTEGER &&\n    Number.isFinite(v.system) && v.system >= 0 && v.system <= Number.MAX_SAFE_INTEGER;\n}\nconst delta = isCpuUsageSnapshot(prev) ? process.cpuUsage(prev) : process.cpuUsage();","typeGuard":"const isCpuUsageSnapshot = (v) =>\n  v != null && typeof v === \"object\" &&\n  [v.user, v.system].every((n) => Number.isFinite(n) && n >= 0 && n <= Number.MAX_SAFE_INTEGER);","tryCatchPattern":"try {\n  delta = process.cpuUsage(prev);\n} catch (err) {\n  if (err.code === \"ERR_INVALID_ARG_VALUE\" && /prevValue/.test(err.message)) {\n    prev = process.cpuUsage(); // take a fresh snapshot and restart the window\n    delta = process.cpuUsage(prev);\n  } else throw err;\n}","preventionTips":["Only feed verbatim snapshots from a previous cpuUsage() call back in — never diffs or hand-built objects","Don't round or mutate stored snapshots","Apply the same validation for threadCpuUsage, which shares the check"],"tags":["process","cpu-usage","argument-validation","node-compat","deno"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}