{"id":"d290d84258712e12","repo":"vitest-dev/vitest","slug":"unexpected-numerical-input-for-memorylimit","errorCode":null,"errorMessage":"Unexpected numerical input for \"memoryLimit\"","messagePattern":"Unexpected numerical input for \"memoryLimit\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/utils/memory-limit.ts","lineNumber":100,"sourceCode":"    }\n  }\n\n  if (typeof input === 'number') {\n    if (input <= 1 && input > 0) {\n      if (percentageReference) {\n        return Math.floor(input * percentageReference)\n      }\n      else {\n        throw new Error(\n          'For a percentage based memory limit a percentageReference must be supplied',\n        )\n      }\n    }\n    else if (input > 1) {\n      return Math.floor(input)\n    }\n    else {\n      throw new Error('Unexpected numerical input for \"memoryLimit\"')\n    }\n  }\n\n  return null\n}\n","sourceCodeStart":82,"sourceCodeEnd":106,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/utils/memory-limit.ts#L82-L106","documentation":"stringToBytes (memory-limit.ts:99-101) throws when the numeric input is not a positive value: a number <= 0, NaN, or otherwise invalid. The branch handles the leftover case after the fraction (0,1] and the absolute (>1) cases are excluded.","triggerScenarios":"Providing a vmMemoryLimit (or calling stringToBytes) with 0, a negative number, or a string that parses to NaN/0 — e.g. '0', '-512', 'abc', or an empty numeric portion.","commonSituations":"Typing vmMemoryLimit: 0 thinking it disables the limit; a negative value from an env-var parse; a malformed string like '--gb' whose numeric portion is empty and resolves to 0.","solutions":["Use a positive absolute value or a valid percentage string for vmMemoryLimit.","Omit vmMemoryLimit entirely (or set to undefined) to let Vitest compute a sensible default.","Sanitize external/env inputs before assigning them to vmMemoryLimit."],"exampleFix":"// before: invalid value\nexport default defineConfig({ test: { vmMemoryLimit: 0 } })\n// or env-derived\nconst limit = Number(process.env.LIMIT) // NaN\n\n// after: valid or omitted\nexport default defineConfig({ test: { vmMemoryLimit: '1GB' } })\n// or sanitize\nconst limit = Number(process.env.LIMIT)\nexport default defineConfig({ test: Number.isFinite(limit) && limit > 1 ? { vmMemoryLimit: limit } : {} })","handlingStrategy":"validation","validationCode":"function validateMemoryLimitNumber(input: unknown) {\n  if (typeof input !== 'string' && typeof input !== 'number') return\n  const numeric = typeof input === 'string' ? Number.parseFloat(input) : input\n  if (!Number.isFinite(numeric) || numeric <= 0) {\n    throw new Error(`memoryLimit must be a positive number or a valid memory string; received '${String(input)}'`)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use positive absolute values or valid percentage strings for vmMemoryLimit.","Sanitize env-derived values with Number.isFinite before assigning.","Omit vmMemoryLimit to accept the computed default rather than setting 0."],"tags":["memory-limit","config","validation","numeric"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}