{"record":{"id":"16c1159297a24f84","repo":"jax-ml/jax","slug":"new-string-config-value-must-be-none-or-of-type-st","errorCode":null,"errorMessage":"new string config value must be None or of type str, got {new_val} of type {type(new_val)}.","messagePattern":"new string config value must be None or of type str, got (.+?) of type (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":859,"sourceCode":"    default: optional string, a default value for the option.\n    help: string, used to populate the flag help information as well as the\n      docstring of the returned context manager.\n    update_global_hook: an optional callback that is called with the updated\n      value of the global state when it is altered or set initially.\n    update_thread_local_hook: an optional callback that is called with the\n      updated value of the thread-local state when it is altered or set\n      initially.\n\n  Returns:\n    A contextmanager to control the thread-local state value.\n  \"\"\"\n  if default is not None and not isinstance(default, str):\n    raise TypeError(f\"Default value must be of type str or None, got {default} \"\n                    f\"of type {getattr(type(default), '__name__', type(default))}\")\n\n  def validator(new_val):\n    if new_val is not None and not isinstance(new_val, str):\n      raise ValueError('new string config value must be None or of type str,'\n                       f' got {new_val} of type {type(new_val)}.')\n\n  return string_or_object_state(\n      name, default, help,\n      update_global_hook=update_global_hook,\n      update_thread_local_hook=update_thread_local_hook,\n      validator=validator,\n      include_in_trace_context=include_in_trace_context)\n\ndef string_or_object_state(\n    name: str,\n    default: Any,\n    help: str,\n    *,\n    update_global_hook: Callable[[Any], None] | None = None,\n    update_thread_local_hook: Callable[[Any], None] | None = None,\n    validator: Callable[[Any], None] | None = None,\n    include_in_jit_key: bool = False,","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L841-L877","documentation":"The validator in optional_string_state (invoked via the parser when the flag is set) requires new values to be None or str; other types (int, Path, bytes, Enum) raise this ValueError.","triggerScenarios":"with my_flag(42):, with my_flag(Path('/x')):, or jax.config.update('jax_my_flag', b'bytes').","commonSituations":"Optional destination flags (cache dirs, dump paths) receiving Path objects or values from typed config loaders.","solutions":["Wrap with str(): str(value) or pass None","Normalize config dataclasses so flag fields are already str|None"],"exampleFix":"// before\nwith jax.my_flag(out_dir):  # out_dir: Path | None\n    ...\n// after\nwith jax.my_flag(str(out_dir) if out_dir else None):\n    ...","handlingStrategy":"validation","validationCode":"if new_val is not None and not isinstance(new_val, str):\n    new_val = str(new_val)","typeGuard":"def as_str_or_none(v):\n    return None if v is None else (v if isinstance(v, str) else str(v))","tryCatchPattern":"try:\n    with my_flag(v):\n        ...\nexcept ValueError:\n    with my_flag(str(v) if v is not None else None):\n        ...","preventionTips":["Convert Path objects at the boundary of your config layer","Annotate flag fields as str | None and validate with a schema loader"],"tags":["jax","config","valueerror","string"],"backgroundTag":"invalid-config-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}