CoplayDev/unity-mcp · error · ValueError
{name} must be a boolean
Error message
{name} must be a boolean What it means
Thrown by _coerce_bool() when the value is not a bool, not 0/1 (int or float), and not a recognized truthy/falsy string ('true'/'false'/'1'/'0'/'yes'/'no'/'on'/'off', case-insensitive, trimmed). The {name} placeholder identifies which boolean option failed (e.g. srgb, readable, generate_mipmaps), surfaced via _normalize_import_settings.
Source
Thrown at Server/src/cli/commands/texture.py:242
return value
_TRUE_STRINGS = {"true", "1", "yes", "on"}
_FALSE_STRINGS = {"false", "0", "no", "off"}
def _coerce_bool(value: Any, name: str) -> bool:
if isinstance(value, bool):
return value
if isinstance(value, (int, float)) and value in (0, 1, 0.0, 1.0):
return bool(value)
if isinstance(value, str):
lowered = value.strip().lower()
if lowered in _TRUE_STRINGS:
return True
if lowered in _FALSE_STRINGS:
return False
raise ValueError(f"{name} must be a boolean")
def _normalize_import_settings(value: Any) -> dict[str, Any]:
if value is None:
return {}
if isinstance(value, str):
value = try_parse_json(value, "import_settings")
if not isinstance(value, dict):
raise ValueError("import_settings must be a JSON object")
result: dict[str, Any] = {}
if "texture_type" in value:
result["textureType"] = _map_enum(
value["texture_type"], _TEXTURE_TYPES)
if "texture_shape" in value:
result["textureShape"] = _map_enum(
value["texture_shape"], _TEXTURE_SHAPES)View on GitHub (pinned to c21bf496bc)
Solutions
- Use true/false, 1/0, yes/no, or on/off for boolean import settings.
- Double-check the value for the field named in the error message.
- Prefer native JSON booleans (`"srgb": true`) over strings where possible.
Example fix
// before
--import-settings '{"readable":"enable"}'
// after
--import-settings '{"readable":true}' Defensive patterns
Strategy: type-guard
Validate before calling
_BOOL = {"true": True, "false": False, "1": True, "0": False, "yes": True, "no": False, "on": True, "off": False}
if isinstance(v, bool) or (isinstance(v, (int, float)) and v in (0, 1)):
b = bool(v)
elif isinstance(v, str) and v.strip().lower() in _BOOL:
b = _BOOL[v.strip().lower()]
else:
raise ValueError(f"{name} must be a boolean") Type guard
def is_coerceable_bool(v) -> bool:
if isinstance(v, bool): return True
if isinstance(v, (int, float)) and v in (0, 1, 0.0, 1.0): return True
return isinstance(v, str) and v.strip().lower() in {"true","false","1","0","yes","no","on","off"} Try / catch
try:
settings = _normalize_import_settings(raw)
except ValueError as e:
print_error(str(e)); sys.exit(1) Prevention
- Use native JSON booleans for import-settings flags.
- Limit boolean strings to the accepted set.
When it happens
Trigger: Passing an import_settings boolean as an unparseable value such as `{"srgb":"yes please"}`, `{"readable":2}`, or `{"generate_mipmaps":"enable"}`. Triggered when _normalize_import_settings hits one of the snake-case boolean keys and calls _coerce_bool.
Common situations: A developer supplies a boolean field with a free-text value, an out-of-range integer, or a non-English word. Common when hand-writing the import-settings JSON without checking accepted string values.
Related errors
- import_settings must be a JSON object
- set-pixels is required
- set-pixels must be a JSON object
- set-pixels requires width and height when pixels are provide
- set-pixels width and height must be positive
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/debe044652a90de4.
Report an issue: GitHub.