{"record":{"id":"8bf6a71ade884374","repo":"CoplayDev/unity-mcp","slug":"package-file-not-found-package-json","errorCode":null,"errorMessage":"Package file not found: {PACKAGE_JSON}","messagePattern":"Package file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"tools/update_versions.py","lineNumber":48,"sourceCode":"import argparse\nimport json\nimport re\nimport sys\nfrom pathlib import Path\n\nREPO_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\")","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/tools/update_versions.py#L30-L66","documentation":"Raised as FileNotFoundError by load_package_version() when MCPForUnity/package.json does not exist on disk. This file is the source of truth for the Unity package version and is the first thing update_versions.py reads (when --version is not supplied). REPO_ROOT is derived from the script's own location (parents[1]), so a wrong CWD or relocated script produces a bad path.","triggerScenarios":"Running update_versions.py from outside the repo, or with the script copied/moved so that parents[1] doesn't resolve to the real repo root. Also fires in a shallow clone or worktree that excludes the MCPForUnity directory.","commonSituations":"Script invoked from a different working directory; the repo was only partially cloned; the script was symlinked or copied to a tools/ directory in a different project; MCPForUnity/package.json was deleted or not yet created in a fresh branch.","solutions":["Confirm the file exists: ls MCPForUnity/package.json from the repo root.","Run the script from within the repo, or ensure parents[1] of the script path resolves to the actual repo root.","If you know the version, bypass auto-detection by passing --version explicitly (update_versions.py only calls load_package_version when --version is absent)."],"exampleFix":"# before — auto-detect fails because package.json is missing\npython3 tools/update_versions.py\n\n# after — supply version explicitly to skip the missing-file read\npython3 tools/update_versions.py --version 9.2.0","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nPACKAGE_JSON = Path(\"MCPForUnity\").resolve() / \"package.json\"\nif not PACKAGE_JSON.is_file():\n    raise SystemExit(f\"{PACKAGE_JSON} not found. Run from the repo root or pass --version.\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run update_versions.py from the repo root so REPO_ROOT resolves correctly.","If package.json is unavailable, pass --version to bypass auto-detection.","Add a CI step that verifies MCPForUnity/package.json exists before version bumping."],"tags":["release-tooling","version-management","path-validation","filesystem"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}