{"record":{"id":"debe044652a90de4","repo":"CoplayDev/unity-mcp","slug":"name-must-be-a-boolean","errorCode":null,"errorMessage":"{name} must be a boolean","messagePattern":"(.+?) must be a boolean","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":242,"sourceCode":"    return value\n\n\n_TRUE_STRINGS = {\"true\", \"1\", \"yes\", \"on\"}\n_FALSE_STRINGS = {\"false\", \"0\", \"no\", \"off\"}\n\n\ndef _coerce_bool(value: Any, name: str) -> bool:\n    if isinstance(value, bool):\n        return value\n    if isinstance(value, (int, float)) and value in (0, 1, 0.0, 1.0):\n        return bool(value)\n    if isinstance(value, str):\n        lowered = value.strip().lower()\n        if lowered in _TRUE_STRINGS:\n            return True\n        if lowered in _FALSE_STRINGS:\n            return False\n    raise ValueError(f\"{name} must be a boolean\")\n\n\ndef _normalize_import_settings(value: Any) -> dict[str, Any]:\n    if value is None:\n        return {}\n    if isinstance(value, str):\n        value = try_parse_json(value, \"import_settings\")\n    if not isinstance(value, dict):\n        raise ValueError(\"import_settings must be a JSON object\")\n\n    result: dict[str, Any] = {}\n\n    if \"texture_type\" in value:\n        result[\"textureType\"] = _map_enum(\n            value[\"texture_type\"], _TEXTURE_TYPES)\n    if \"texture_shape\" in value:\n        result[\"textureShape\"] = _map_enum(\n            value[\"texture_shape\"], _TEXTURE_SHAPES)","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L224-L260","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n--import-settings '{\"readable\":\"enable\"}'\n// after\n--import-settings '{\"readable\":true}'","handlingStrategy":"type-guard","validationCode":"_BOOL = {\"true\": True, \"false\": False, \"1\": True, \"0\": False, \"yes\": True, \"no\": False, \"on\": True, \"off\": False}\nif isinstance(v, bool) or (isinstance(v, (int, float)) and v in (0, 1)):\n    b = bool(v)\nelif isinstance(v, str) and v.strip().lower() in _BOOL:\n    b = _BOOL[v.strip().lower()]\nelse:\n    raise ValueError(f\"{name} must be a boolean\")","typeGuard":"def is_coerceable_bool(v) -> bool:\n    if isinstance(v, bool): return True\n    if isinstance(v, (int, float)) and v in (0, 1, 0.0, 1.0): return True\n    return isinstance(v, str) and v.strip().lower() in {\"true\",\"false\",\"1\",\"0\",\"yes\",\"no\",\"on\",\"off\"}","tryCatchPattern":"try:\n    settings = _normalize_import_settings(raw)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Use native JSON booleans for import-settings flags.","Limit boolean strings to the accepted set."],"tags":["cli","validation","texture","input-validation","import-settings"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}