{"id":"992251e883c116e3","repo":"jestjs/jest","slug":"unexpected-numerical-input","errorCode":null,"errorMessage":"Unexpected numerical input","messagePattern":"Unexpected numerical input","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/stringToBytes.ts","lineNumber":84,"sourceCode":"      input = Number.parseFloat(input);\n    }\n  }\n\n  if (typeof input === 'number') {\n    if (input === 0) {\n      return 0;\n    } else if (input <= 1 && input > 0) {\n      if (percentageReference) {\n        return Math.floor(input * percentageReference);\n      } else {\n        throw new Error(\n          'For a percentage based memory limit a percentageReference must be supplied',\n        );\n      }\n    } else if (input > 1) {\n      return Math.floor(input);\n    } else {\n      throw new Error('Unexpected numerical input');\n    }\n  }\n\n  throw new Error('Unexpected input');\n}\n\n// https://github.com/import-js/eslint-plugin-import/issues/1590\nexport default stringToBytes;\n","sourceCodeStart":66,"sourceCodeEnd":93,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/stringToBytes.ts#L66-L93","documentation":"The numeric branch in stringToBytes handles 0 (returns 0), fractions in (0,1] (percentage), and values > 1 (bytes). Any other number - negatives and NaN - falls to the else and throws 'Unexpected numerical input'. This guards against nonsensical memory limits like -1.","triggerScenarios":"Calling stringToBytes(-1), stringToBytes(NaN), or a parsed string that yields a negative number.","commonSituations":"Arithmetic that underflows to negative; parseFloat on garbage yielding NaN that flows in; config typos producing negative memory values.","solutions":["Provide a positive number of bytes (> 1) or a valid fraction in (0,1]","Sanitize inputs to ensure they are finite and >= 0 before calling","Use a descriptive string like '1gb' instead of raw numbers"],"exampleFix":"// before\nstringToBytes(-1)\n// after\nstringToBytes('1gb')","handlingStrategy":"validation","validationCode":"function isFiniteNonNegative(n: number): boolean {\n  return Number.isFinite(n) && n >= 0;\n}\nif (!isFiniteNonNegative(value)) throw new Error('memory limit must be a finite non-negative number');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate memory limits are positive and finite before conversion","Reject negative numbers at the config boundary"],"tags":["memory","config","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}