{"record":{"id":"a4ed31a3d88ab4f8","repo":"Hmbown/CodeWhale","slug":"cargo-metadata-failed-with-exit-code-process-retu","errorCode":null,"errorMessage":"cargo metadata failed with exit code {process.returncode}{suffix}","messagePattern":"cargo metadata failed with exit code (.+?)(.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"scripts/release/validate-crate-publish-order.py","lineNumber":48,"sourceCode":"\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:\n        raise ValidationError(f\"Cargo metadata is not valid JSON: {error}\") from error\n    if not isinstance(metadata, dict):\n        raise ValidationError(\"Cargo metadata root must be an object\")\n    return metadata\n\n\ndef workspace_packages(metadata: dict[str, Any]) -> list[dict[str, Any]]:\n    members = metadata.get(\"workspace_members\")\n    packages = metadata.get(\"packages\")\n    if not isinstance(members, list) or not isinstance(packages, list):\n        raise ValidationError(\"Cargo metadata must contain workspace_members and packages lists\")","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/release/validate-crate-publish-order.py#L30-L66","documentation":"The validator shells out to 'cargo metadata --locked --format-version 1 --no-deps' and that subprocess exited non-zero. The workspace inventory (names, versions, path dependencies) is derived from this metadata, so any cargo failure is fatal; the message embeds the exit code and the stripped stderr detail when present.","triggerScenarios":"Cargo.lock is out of date with the manifests while --locked forbids regeneration; a workspace member's Cargo.toml has a syntax or resolution error; a renamed/removed crate leaves stale references; cargo itself fails to start in the environment.","commonSituations":"Editing dependencies or adding a crate without running a build to refresh Cargo.lock; switching toolchains; a merge that combined manifest changes but not lockfile changes.","solutions":["Reproduce and read the real error: cargo metadata --locked --format-version 1 --no-deps","If the complaint is lockfile drift, refresh it (e.g. cargo update -w or any build) and commit Cargo.lock","Fix the manifest error cargo names (parse error, missing field, bad version requirement)","Confirm cargo works at all in this environment: cargo --version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Pre-flight the exact metadata query before the release run:\nimport subprocess, sys\n\nprobe = subprocess.run(\n    [\"cargo\", \"metadata\", \"--locked\", \"--format-version\", \"1\", \"--no-deps\"],\n    capture_output=True, text=True,\n)\nif probe.returncode != 0:\n    sys.exit(f\"fix cargo first: {probe.stderr.strip()}\")","typeGuard":null,"tryCatchPattern":"try:\n    metadata = load_metadata(args.metadata_file)\nexcept ValidationError as e:\n    print(f\"release validation aborted: {e}\", file=sys.stderr)\n    sys.exit(1)","preventionTips":["Keep Cargo.lock committed and refreshed whenever manifests change, since the validator runs with --locked","Run cargo metadata (or any build) after manifest edits before invoking release scripts"],"tags":["cargo","release","lockfile","python","metadata"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}