google/python-fire · error · InvalidEnumValue

Invalid enum value: {0} for enum type: Operating System. Val

Error message

Invalid enum value: {0} for enum type: Operating System. Valid values: [{1}].

What it means

OperatingSystem.FromId maps a short OS id (e.g. 'LINUX', 'WINDOWS') to an OperatingSystem enum member. If no member's id matches the supplied os_id and error_on_unknown is true, it raises InvalidEnumValue listing the valid ids. If os_id is falsy it returns None instead of raising.

Source

Thrown at fire/console/platforms.py:136

    Args:
      os_id: str, The operating system id to parse
      error_on_unknown: bool, True to raise an exception if the id is unknown,
        False to just return None.

    Raises:
      InvalidEnumValue: If the given value cannot be parsed.

    Returns:
      OperatingSystemTuple, One of the OperatingSystem constants or None if the
      input is None.
    """
    if not os_id:
      return None
    for operating_system in OperatingSystem._ALL:
      if operating_system.id == os_id:
        return operating_system
    if error_on_unknown:
      raise InvalidEnumValue(os_id, 'Operating System',
                             [value.id for value in OperatingSystem._ALL])
    return None

  @staticmethod
  def Current():
    """Determines the current operating system.

    Returns:
      OperatingSystemTuple, One of the OperatingSystem constants or None if it
      cannot be determined.
    """
    if os.name == 'nt':
      return OperatingSystem.WINDOWS
    elif 'linux' in sys.platform:
      return OperatingSystem.LINUX
    elif 'darwin' in sys.platform:
      return OperatingSystem.MACOSX
    elif 'cygwin' in sys.platform:

View on GitHub (pinned to 716bbc23d7)

Solutions

  1. Print the valid ids (the error lists them) and use one of those exact strings.
  2. Map your platform string to a known id before calling (e.g. 'Darwin' -> 'MACOSX' depending on the library's id set).
  3. Use OperatingSystem.Current() instead of manual id construction.
  4. Pass error_on_unknown=False if a None result is acceptable.

Example fix

// before
os_enum = OperatingSystem.FromId(platform.system(), error_on_unknown=True)  # 'Darwin'
// after
os_enum = OperatingSystem.Current()
Defensive patterns

Strategy: validation

Validate before calling

valid_ids = [v.id for v in OperatingSystem._ALL]
if os_id and os_id not in valid_ids:
    raise SystemExit(f'{os_id!r} not in {valid_ids}')

Type guard

def is_known_os_id(os_id: str) -> bool:
    return os_id in {v.id for v in OperatingSystem._ALL}

Try / catch

try:
    os_enum = OperatingSystem.FromId(os_id, error_on_unknown=True)
except InvalidEnumValue as e:
    print(f'Unknown OS id {os_id}; valid: {e}'); sys.exit(2)

Prevention

When it happens

Trigger: Calling OperatingSystem.FromId('mac', error_on_unknown=True) or FromId(platform.system()) with a raw string that is not one of the library's recognized ids; usually caused by feeding unnormalized platform strings into the enum lookup.

Common situations: Deriving the OS from platform.system() ('Darwin' vs expected ids), user-supplied config values, or a library version where the id set changed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of google/python-fire@716bbc23d7 (2026-08-28). Data as JSON: /api/errors/bd8a96a46ecc51dc. Report an issue: GitHub.