{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/stringToBytes.ts#L66-L93","documentation":"Thrown by stringToBytes when the numeric input is a number less than or equal to 0 and not exactly 0. The accepted branches are: 0 (returns 0), (0,1] (percentage), and >1 (absolute bytes). Any negative number, or values like NaN after parsing that slip past the typeof check, hit the final else.","triggerScenarios":"Passing a negative memory value such as '-512mb' or -100; a percentage like '-10%'; or a numeric input that resolves to a negative number after unit parsing.","commonSituations":"Sign errors in computed memory limits; user typos adding a stray '-' before a unit; off-by-one arithmetic that produces a negative cap.","solutions":["Use a non-negative value for the memory limit","Validate input >= 0 before calling stringToBytes","If computing dynamically, clamp with Math.max(0, value)"],"exampleFix":"// before\nstringToBytes('-512mb');\n\n// after\nstringToBytes('512mb');","handlingStrategy":"validation","validationCode":"function assertNonNegativeBytes(input: string | number): void {\n  const num = typeof input === 'number' ? input : parseFloat(input);\n  if (num < 0) {\n    throw new Error('Memory limit must be non-negative');\n  }\n}","typeGuard":"function isNonNegativeMemoryValue(value: string | number): boolean {\n  const num = typeof value === 'number' ? value : parseFloat(value);\n  return !Number.isNaN(num) && num >= 0;\n}","tryCatchPattern":null,"preventionTips":["Clamp computed memory values with Math.max(0, value)","Validate user-supplied memory strings before passing to stringToBytes","Reject negative values at the config/UI layer"],"tags":["memory","config","argument-validation"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}