apache/beam · error · ValueError

Unrecognized value pattern.

Error message

Unrecognized value pattern.

What it means

_parse_storage_size_str parses a storage size string like '512MB' by regex-extracting a trailing non-digit suffix. If the value contains no trailing non-digit characters (i.e., it is purely numeric with no unit), the regex fails to match and this error is raised. The library requires every storage size to carry an explicit unit suffix.

Solutions

  1. Add a unit suffix to the value, e.g. '100' -> '100MB' or '1024KB'.
  2. Check that the value does not have hidden whitespace or non-ASCII digits preventing the suffix regex from matching.
  3. If the unit should be implied, pre-normalize the string before passing it as a hint.

Example fix

// before
options.view_as(DebugOptions).add_resource_hint('memory_mb=1024')
// after
options.view_as(DebugOptions).add_resource_hint('memory_mb=1024MB')  # unit suffix required
Defensive patterns

Strategy: validation

Validate before calling

import re
assert re.search(r'\d+[KMGT]?B?$', value) and re.search(r'\D', value), f"storage value {value!r} needs a unit suffix (e.g. '512MB')"

Type guard

def has_unit_suffix(value: str) -> bool:
    return bool(re.search(r'\D', value)) and isinstance(value, str)

Try / catch

try:
    hints = parse_resource_hints(raw_hints)
except ValueError as e:
    if 'Unrecognized value pattern' in str(e):
        log.error('Storage hint %r lacks a unit suffix (e.g. 512MB)', e); raise

Prevention

When it happens

Trigger: Calling parse_resource_hints with a storage hint value like '100' or '100 ' with no unit suffix; the regex r'.*?(\D+)$' returns None and ValueError('Unrecognized value pattern.') is raised.

Common situations: Users specify resource hints in pipeline options or YAML templates and forget the unit (e.g. 'memory_mb=1024' instead of '1024MB'); values copied from configs where the unit lives in the key name rather than the value.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/39013217594d75df. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/transforms/resources.py:134

      raise ValueError("Input must be a string or integer.")

    value = value.strip().replace(" ", "")
    units = {
        'PiB': 2**50,
        'TiB': 2**40,
        'GiB': 2**30,
        'MiB': 2**20,
        'KiB': 2**10,
        'PB': 10**15,
        'TB': 10**12,
        'GB': 10**9,
        'MB': 10**6,
        'KB': 10**3,
        'B': 1,
    }
    match = re.match(r'.*?(\D+)$', value)
    if not match:
      raise ValueError("Unrecognized value pattern.")

    suffix = match.group(1)
    if suffix not in units:
      raise ValueError("Unrecognized unit.")
    multiplier = units[suffix]
    value = value[:-len(suffix)]

    return str(round(float(value) * multiplier)).encode('ascii')

  @staticmethod
  def _use_max(v1, v2):
    return str(max(int(v1), int(v2))).encode('ascii')

  @staticmethod
  def _use_sum(v1, v2):
    return str(int(v1) + int(v2)).encode('ascii')

View on GitHub (pinned to 12126d8942)