{"record":{"id":"5d00aed1800450c5","repo":"Hmbown/CodeWhale","slug":"could-not-read-cargo-metadata-error","errorCode":null,"errorMessage":"could not read Cargo metadata: {error}","messagePattern":"could not read Cargo metadata: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"scripts/release/validate-crate-publish-order.py","lineNumber":37,"sourceCode":"\n\ndef parse_args() -> argparse.Namespace:\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\n        \"--metadata-file\",\n        type=Path,\n        help=\"Read Cargo metadata from this file instead of invoking cargo (tests only).\",\n    )\n    parser.add_argument(\"crates\", nargs=\"+\", help=\"Maintained publication order\")\n    return parser.parse_args()\n\n\ndef load_metadata(metadata_file: Path | None) -> dict[str, Any]:\n    if metadata_file is not None:\n        try:\n            raw = metadata_file.read_text(encoding=\"utf-8\")\n        except OSError as error:\n            raise ValidationError(f\"could not read Cargo metadata: {error}\") from error\n    else:\n        process = subprocess.run(\n            [\"cargo\", \"metadata\", \"--locked\", \"--format-version\", \"1\", \"--no-deps\"],\n            check=False,\n            capture_output=True,\n            text=True,\n        )\n        if process.returncode != 0:\n            detail = process.stderr.strip()\n            suffix = f\": {detail}\" if detail else \"\"\n            raise ValidationError(\n                f\"cargo metadata failed with exit code {process.returncode}{suffix}\"\n            )\n        raw = process.stdout\n\n    try:\n        metadata = json.loads(raw)\n    except json.JSONDecodeError as error:","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/release/validate-crate-publish-order.py#L19-L55","documentation":"load_metadata() raises this ValidationError when reading the file passed via --metadata-file fails with an OSError. The --metadata-file flag exists so the script's tests can feed canned cargo metadata JSON instead of invoking cargo; pointing it at a missing, unreadable, or wrong-type path produces this error with the underlying OS detail appended.","triggerScenarios":"Passing --metadata-file with a path that does not exist; the file or a parent directory lacks read permission; the path is a directory; a test fixture was moved or renamed without updating the test.","commonSituations":"Running the script or its unit tests with a stale fixture path after a repo reorganization, or a typo in the --metadata-file argument.","solutions":["Verify the path exists and is a readable file: test -f <path>","Regenerate the fixture: cargo metadata --locked --format-version 1 --no-deps > <path>","Omit --metadata-file entirely to have the script invoke cargo metadata directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nmetadata_file = Path(args_metadata_file)\nif metadata_file is not None and not metadata_file.is_file():\n    raise SystemExit(f\"metadata file not readable: {metadata_file}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In tests, generate fixtures into tmp_path instead of referencing checked-in paths that rot","Prefer omitting --metadata-file outside tests so the script reads live cargo metadata"],"tags":["python","release","file-io","cargo","fixtures"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}