jestjs/jest · error · Error

Unexpected input

Error message

Unexpected input

What it means

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.

Source

Thrown at packages/jest-config/src/stringToBytes.ts:88

  if (typeof input === 'number') {
    if (input === 0) {
      return 0;
    } else if (input <= 1 && input > 0) {
      if (percentageReference) {
        return Math.floor(input * percentageReference);
      } else {
        throw new Error(
          'For a percentage based memory limit a percentageReference must be supplied',
        );
      }
    } else if (input > 1) {
      return Math.floor(input);
    } else {
      throw new Error('Unexpected numerical input');
    }
  }

  throw new Error('Unexpected input');
}

// https://github.com/import-js/eslint-plugin-import/issues/1590
export default stringToBytes;

View on GitHub (pinned to f49721c78e)

Solutions

  1. Use a recognized unit suffix: k/kb/kib/m/mb/mib/g/gb/gib, or '%', or a plain number
  2. Remove stray characters from the value
  3. Provide null/undefined instead of an empty string if no limit is intended

Example fix

// before
stringToBytes('512mxb')
// after
stringToBytes('512mb')
Defensive patterns

Strategy: validation

Validate before calling

const MEM_RE = /^(\d+(\.\d+)?)(kib|mib|gib|kb|mb|gb|k|m|g|%)?$/i;
function isValidMemoryString(s: string): boolean {
  return MEM_RE.test(s.trim());
}

Prevention

When it happens

Trigger: 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.

Common situations: User-typed memory strings with typos in units; config values copied with stray characters; empty-string defaults.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/a029a0876a121837.json. Report an issue: GitHub.