{"record":{"id":"22db0bc89b3637fa","repo":"CoplayDev/unity-mcp","slug":"no-version-found-in-package-json","errorCode":null,"errorMessage":"No version found in package.json","messagePattern":"No version found in package\\.json","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/update_versions.py","lineNumber":54,"sourceCode":"REPO_ROOT = Path(__file__).resolve().parents[1]\nPACKAGE_JSON = REPO_ROOT / \"MCPForUnity\" / \"package.json\"\nMANIFEST_JSON = REPO_ROOT / \"manifest.json\"\nPYPROJECT_TOML = REPO_ROOT / \"Server\" / \"pyproject.toml\"\nSERVER_README = REPO_ROOT / \"Server\" / \"README.md\"\nROOT_README = REPO_ROOT / \"README.md\"\nZH_README = REPO_ROOT / \"docs\" / \"i18n\" / \"README-zh.md\"\n\n\ndef load_package_version() -> str:\n    \"\"\"Load version from package.json.\"\"\"\n    if not PACKAGE_JSON.exists():\n        raise FileNotFoundError(f\"Package file not found: {PACKAGE_JSON}\")\n\n    package_data = json.loads(PACKAGE_JSON.read_text(encoding=\"utf-8\"))\n    version = package_data.get(\"version\")\n\n    if not version:\n        raise ValueError(\"No version found in package.json\")\n\n    return version\n\n\ndef update_package_json(new_version: str, dry_run: bool = False) -> bool:\n    \"\"\"Update version in MCPForUnity/package.json.\"\"\"\n    if not PACKAGE_JSON.exists():\n        print(f\"Warning: {PACKAGE_JSON.relative_to(REPO_ROOT)} not found\")\n        return False\n\n    package_data = json.loads(PACKAGE_JSON.read_text(encoding=\"utf-8\"))\n    current_version = package_data.get(\"version\", \"unknown\")\n\n    if current_version == new_version:\n        print(f\"✓ {PACKAGE_JSON.relative_to(REPO_ROOT)} already at v{new_version}\")\n        return False\n\n    print(","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/tools/update_versions.py#L36-L72","documentation":"Raised as ValueError by load_package_version() when MCPForUnity/package.json exists and parses as valid JSON, but either has no \"version\" key at all or the key's value is falsy (null, empty string). The script cannot proceed without a version to propagate to the other files.","triggerScenarios":"package.json was hand-edited and the version field was deleted or commented out (JSON has no comments, but a broken edit can leave it absent); a code generator or merge conflict produced a package.json without the version field; the field exists but is set to null or \"\".","commonSituations":"A merge conflict in package.json left the version field unresolved or removed; an automated tool rewrote package.json and dropped the version key; the file is a template or stub that was never populated.","solutions":["Open MCPForUnity/package.json and confirm a top-level \"version\" key exists with a semver string, e.g. \"version\": \"9.2.0\".","If the field is missing, add it. If it is null/empty, set it to the current release version.","Validate the JSON with python3 -c \"import json; print(json.load(open('MCPForUnity/package.json')).get('version'))\" to confirm the key resolves.","Alternatively, pass --version to update_versions.py to bypass auto-detection entirely."],"exampleFix":"// before — MCPForUnity/package.json\n{\n  \"name\": \"io.coplay.mcpforunity\"\n}\n\n// after\n{\n  \"name\": \"io.coplay.mcpforunity\",\n  \"version\": \"9.2.0\"\n}","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndata = json.loads(Path(\"MCPForUnity/package.json\").read_text())\nversion = data.get(\"version\")\nif not version:\n    raise SystemExit(\"package.json has no 'version' field. Set it before running.\")\nprint(f\"Detected version: {version}\")","typeGuard":"def has_valid_version(package_path: Path) -> bool:\n    try:\n        data = json.loads(package_path.read_text(encoding=\"utf-8\"))\n    except (OSError, json.JSONDecodeError):\n        return False\n    return bool(data.get(\"version\"))","tryCatchPattern":null,"preventionTips":["Ensure package.json always has a top-level \"version\" key after merges.","Validate package.json with a JSON linter or schema check before running the script.","Pass --version explicitly in CI to avoid depending on auto-detection."],"tags":["release-tooling","version-management","json-validation","config"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}