{"id":"a029a0876a121837","repo":"jestjs/jest","slug":"unexpected-input","errorCode":null,"errorMessage":"Unexpected input","messagePattern":"Unexpected input","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/stringToBytes.ts","lineNumber":88,"sourceCode":"  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":70,"sourceCodeEnd":93,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/stringToBytes.ts#L70-L93","documentation":"The final fallthrough in stringToBytes. It is reached when, after all parsing, the input is neither null/undefined nor a recognized number/unit. Typically a string with no numeric component (e.g. \"abc\") or an unsupported unit. The function signature constrains input, but runtime garbage still reaches here.","triggerScenarios":"Calling stringToBytes(\"abc\"), stringToBytes(\"512xb\") (unknown unit), or stringToBytes(\"\"); the regex match yields no numeric segment so the string is never converted to a number.","commonSituations":"User-typed memory strings with typos in units; config values copied with stray characters; empty-string defaults.","solutions":["Use a recognized unit suffix: k/kb/kib/m/mb/mib/g/gb/gib, or '%', or a plain number","Remove stray characters from the value","Provide null/undefined instead of an empty string if no limit is intended"],"exampleFix":"// before\nstringToBytes('512mxb')\n// after\nstringToBytes('512mb')","handlingStrategy":"validation","validationCode":"const MEM_RE = /^(\\d+(\\.\\d+)?)(kib|mib|gib|kb|mb|gb|k|m|g|%)?$/i;\nfunction isValidMemoryString(s: string): boolean {\n  return MEM_RE.test(s.trim());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document the supported unit vocabulary at the config boundary","Test memory-string parsing with a table of valid and invalid cases"],"tags":["memory","config","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}