{"record":{"id":"cc9341b183b56a34","repo":"jax-ml/jax","slug":"new-enum-value-must-be-in-enum-values-got-new","errorCode":null,"errorMessage":"new enum value must be in {enum_values}, got {new_val} of type {type(new_val)}.","messagePattern":"new enum value must be in (.+?), got (.+?) of type (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":514,"sourceCode":"      JIT cache key.\n    extra_validator: optional function to validate the value of the config\n      option.\n\n  Returns:\n    A contextmanager to control the thread-local state value.\n  \"\"\"\n  if not isinstance(default, str):\n    raise TypeError(f\"Default value must be of type str, got {default} \"\n                    f\"of type {getattr(type(default), '__name__', type(default))}\")\n  name = name.lower()\n  default = os.getenv(name.upper(), default)\n  if default not in enum_values:\n    raise ValueError(f\"Invalid value \\\"{default}\\\" for JAX flag {name}\")\n  config._contextmanager_flags.add(name)\n\n  def parser(new_val):\n    if type(new_val) is not str or new_val not in enum_values:\n      raise ValueError(f\"new enum value must be in {enum_values}, \"\n                       f\"got {new_val} of type {type(new_val)}.\")\n    if extra_validator is not None:\n      extra_validator(new_val)\n    return new_val\n\n  s = State[str](\n      name,\n      default,\n      help,\n      update_global_hook=update_global_hook,\n      update_thread_local_hook=update_thread_local_hook,\n      parser=parser,\n      include_in_jit_key=include_in_jit_key,\n      include_in_trace_context=include_in_trace_context,\n  )\n  config.add_option(\n      name, s, 'enum',\n      meta_args=[],","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L496-L532","documentation":"The parser created by enum_state rejects any new value set on the flag that is not a str (exact type check, subclasses excluded) or is not in enum_values. It fires when calling the context manager or config update with a bad value.","triggerScenarios":"with my_flag(MyEnum.FOO): ... (Enum member instead of its string value), or jax.config.update('my_flag', 'invalid').","commonSituations":"Programmatically toggling an enum-backed flag (profiler trace level, compilation cache mode) with an Enum object or a typo'd string.","solutions":["Pass the string member: with my_flag(MyEnum.FOO.value):","Double-check the string is one of the enum_values listed in the flag's help"],"exampleFix":"// before\nwith jax.my_flag(MyEnum.FOO):\n    ...\n// after\nwith jax.my_flag('foo'):\n    ...","handlingStrategy":"validation","validationCode":"if not (type(new_val) is str and new_val in enum_values):\n    raise ValueError(f'expected one of {enum_values}, got {new_val!r}')","typeGuard":"def is_enum_value(v, values) -> bool:\n    return type(v) is str and v in values","tryCatchPattern":"try:\n    with my_flag(val):\n        ...\nexcept ValueError as e:\n    if 'new enum value' in str(e):\n        val = DEFAULT; my_flag(val).__enter__()","preventionTips":["Pass MyEnum.FOO.value rather than Enum members","Whitelist dynamic values against enum_values before entering the context manager"],"tags":["jax","config","valueerror","enum"],"backgroundTag":"invalid-config-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}