{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/stringToBytes.ts#L70-L93","documentation":"The terminal throw at the end of stringToBytes, reached when none of the preceding branches return. This happens when input is a string whose trailing characters do not match any known unit (%, kb, k, kib, mb, m, mib, gb, g, gib), or when the regex match fails to capture numericString/trailingChars for a non-numeric-ending input.","triggerScenarios":"Passing an unrecognized unit like '512xb', '5tb', or '5tb'; a string like 'abc' where the last char is non-numeric but no valid unit is captured; or input of an unexpected type that bypassed all branches.","commonSituations":"Typos in memory units; unsupported units (terabytes, bits); copy-pasting values formatted with spaces or commas that break the regex.","solutions":["Use a supported unit: kb, kib, mb, mib, gb, gib, or their single-letter forms (k, m, g), or %","Strip whitespace and commas before calling stringToBytes","If you need a larger unit, pre-convert to gb (e.g. 2tb -> 2048gb)"],"exampleFix":"// before\nstringToBytes('512tb');\n\n// after\nstringToBytes('524288gb');","handlingStrategy":"validation","validationCode":"const SUPPORTED_UNITS = ['%', 'kb', 'kib', 'mb', 'mib', 'gb', 'gib', 'k', 'm', 'g'];\nfunction assertSupportedUnit(input: string): void {\n  const match = input.match(/(.*?)([^\\d.-]+)$/i);\n  const unit = match?.[2]?.toLowerCase();\n  if (unit && !SUPPORTED_UNITS.includes(unit)) {\n    throw new Error(`Unsupported memory unit '${unit}'. Supported: ${SUPPORTED_UNITS.join(', ')}`);\n  }\n}","typeGuard":"const UNIT_RE = /^(\\d+(?:\\.\\d+)?)(kib|mib|gib|kb|mb|gb|k|m|g|%)$/i;\nfunction isSupportedMemoryString(value: unknown): boolean {\n  return typeof value === 'string' && UNIT_RE.test(value.trim());\n}","tryCatchPattern":null,"preventionTips":["Restrict the unit vocabulary at the input boundary","Strip whitespace and commas from memory strings before parsing","Convert unsupported units (tb, pb) to gb upstream"],"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"}