Hmbown/CodeWhale · error · ValidationError
Cargo metadata root must be an object
Error message
Cargo metadata root must be an object
What it means
The metadata parsed as JSON but the root value is not an object (for example a top-level array or string). cargo metadata --format-version 1 always produces a root object, so this guard rejects structurally wrong input before the keys are read.
Source
Thrown at scripts/release/validate-crate-publish-order.py:58
["cargo", "metadata", "--locked", "--format-version", "1", "--no-deps"],
check=False,
capture_output=True,
text=True,
)
if process.returncode != 0:
detail = process.stderr.strip()
suffix = f": {detail}" if detail else ""
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)View on GitHub (pinned to 8880682c63)
Solutions
- Replace the fixture with the complete cargo metadata document: cargo metadata --locked --format-version 1 --no-deps > <metadata-file>
- If the fixture must be minimal, keep the root an object containing at least workspace_members and packages
Defensive patterns
Strategy: type-guard
Type guard
def is_cargo_metadata_root(value: object) -> bool:
return isinstance(value, dict) Prevention
- Never store a projection (e.g. just the packages array) as a metadata fixture; save the full document
- Add a fixture test that asserts the root is an object with workspace_members and packages lists
When it happens
Trigger: A --metadata-file fixture containing only a projection such as the 'packages' array instead of the full metadata object; a JSON string or number at the root.
Common situations: Building test fixtures by extracting one field of cargo metadata output rather than saving the whole document.
Related errors
- Cargo metadata must contain workspace_members and packages l
- Cargo metadata is not valid JSON: {error}
- Cargo metadata omits workspace package ids: {missing_ids}
- workspace package is missing a name
- Cargo metadata dependencies for {dependent} must be a list
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/bf7a613933cef6b7.
Report an issue: GitHub.