Hmbown/CodeWhale · error · ValidationError
Cargo metadata must contain workspace_members and packages…
Error message
Cargo metadata must contain workspace_members and packages lists
What it means
workspace_packages requires the metadata dict to contain both 'workspace_members' and 'packages' as lists and raises this ValidationError if either is missing or of the wrong type. These two fields are the minimum shape needed to map member ids to package manifests.
Solutions
- Regenerate metadata with the project's pinned cargo toolchain: cargo metadata --locked --format-version 1 --no-deps
- Ensure the JSON includes both workspace_members and packages as arrays
- Fix the key names/types if constructing metadata manually for tests
- Check rustup/cargo version matches what CI uses
Example fix
// before (fixture missing key)
{"packages": [...]}
// after
{"packages": [...], "workspace_members": ["id-1"]} Defensive patterns
Strategy: validation
Validate before calling
import json
m = json.load(open("cargo-metadata.json"))
missing = [k for k in ("workspace_members", "packages") if not isinstance(m.get(k), list)]
if missing:
raise SystemExit(f"metadata missing list fields: {missing}") Type guard
def has_workspace_shape(m) -> bool:
return isinstance(m, dict) and isinstance(m.get("workspace_members"), list) and isinstance(m.get("packages"), list) Try / catch
try:
validate_publish_order(metadata_file)
except ValidationError as e:
if "workspace_members and packages" in str(e):
print("metadata shape wrong; regenerate with the pinned cargo version") Prevention
- Pin the cargo toolchain used to generate metadata
- Test fixtures must mirror real cargo metadata including both list fields
- Re-generate rather than hand-trim metadata files
When it happens
Trigger: Metadata produced by an incompatible cargo version lacking these fields; a hand-built or mocked metadata dict omitting them; a types field typo like 'workspace_member' or nested metadata under a different key.
Common situations: Using a very old/new cargo whose metadata schema differs; feeding the validator a custom JSON fixture for tests that doesn't mirror real cargo metadata; hand-trimming the metadata file and dropping required keys.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Cargo metadata root must be an object
- Cargo metadata dependencies for
- Cargo metadata is not valid JSON
- Cargo metadata omits workspace package ids
- invalid : top level must be an object
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/ae3d913892ac3d73.
Report an issue: GitHub.
Appendix: 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 433685b202)