Hmbown/CodeWhale · error · ValidationError

Cargo metadata must contain workspace_members and packages l

Error message

Cargo metadata must contain workspace_members and packages lists

What it means

workspace_packages() requires both 'workspace_members' and 'packages' to be present as JSON arrays in the metadata; one of them was missing or not a list. Without both, member ids cannot be mapped to package records.

Source

Thrown at scripts/release/validate-crate-publish-order.py:66

            raise ValidationError(
                f"cargo metadata failed with exit code {process.returncode}{suffix}"
            )
        raw = process.stdout

    try:
        metadata = json.loads(raw)
    except json.JSONDecodeError as error:
        raise ValidationError(f"Cargo metadata is not valid JSON: {error}") from error
    if not isinstance(metadata, dict):
        raise ValidationError("Cargo metadata root must be an object")
    return metadata


def workspace_packages(metadata: dict[str, Any]) -> list[dict[str, Any]]:
    members = metadata.get("workspace_members")
    packages = metadata.get("packages")
    if not isinstance(members, list) or not isinstance(packages, list):
        raise ValidationError("Cargo metadata must contain workspace_members and packages lists")

    packages_by_id = {
        package.get("id"): package
        for package in packages
        if isinstance(package, dict) and isinstance(package.get("id"), str)
    }
    missing_ids = [member for member in members if member not in packages_by_id]
    if missing_ids:
        raise ValidationError(
            "Cargo metadata omits workspace package ids: " + ", ".join(missing_ids)
        )
    return [packages_by_id[member] for member in members]


def validate_order(
    packages: list[dict[str, Any]], ordered_crates: list[str]
) -> tuple[str, dict[str, bool]]:
    duplicate_crates = sorted(

View on GitHub (pinned to 8880682c63)

Solutions

  1. Regenerate the metadata fixture with the exact command the script uses: cargo metadata --locked --format-version 1 --no-deps
  2. If editing by hand, ensure both workspace_members and packages are JSON arrays at the root
Defensive patterns

Strategy: type-guard

Type guard

def has_required_lists(metadata: dict) -> bool:
    return isinstance(metadata.get("workspace_members"), list) and isinstance(metadata.get("packages"), list)

Prevention

When it happens

Trigger: A fixture built from a partial copy of cargo metadata that omits one key; a key whose value is null, an object, or a string; metadata from a hypothetical future format-version that renames the keys.

Common situations: Hand-minimized test fixtures for the validator that dropped a required key.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/ae3d913892ac3d73. Report an issue: GitHub.