can1357/oh-my-pi · error · Error

${(result.stderr || result.stdout).replace(/\s+/g, " ").trim

Error message

${(result.stderr || result.stdout).replace(/\s+/g, " ").trim()}

What it means

cargoWorkspacePackages() shells out to cargo (e.g. `cargo metadata`) with allowNonZero: true, so a failing cargo invocation returns instead of throwing. The function then surfaces cargo's stderr/stdout (whitespace-collapsed and sanitized) as the thrown message — i.e. this is cargo's own error text relayed to the caller.

Source

Thrown at packages/coding-agent/src/cleanse/checkers.ts:490

				args: ["test", "--no-fail-fast", "--all-targets", ...packageArgs, "--message-format=json"],
				parser: "rust-test",
			});
		}
	}
}

async function cargoWorkspacePackages(state: DiscoveryState, root: string, cargo: string): Promise<string[]> {
	const manifest = path.resolve(state.projectCwd, root, "Cargo.toml");
	const result = await ptree.exec(
		[cargo, "metadata", "--no-deps", "--format-version=1", "--manifest-path", manifest],
		{
			cwd: path.resolve(state.projectCwd, root),
			stderr: "full",
			allowNonZero: true,
		},
	);
	if (!result.ok) {
		throw new Error(
			sanitizeText(result.stderr || result.stdout)
				.replace(/\s+/g, " ")
				.trim(),
		);
	}
	let parsed: unknown;
	try {
		parsed = JSON.parse(result.stdout);
	} catch (error) {
		throw new Error(`invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
	}
	if (!isRecord(parsed)) throw new Error("metadata root is not an object");
	const workspaceMembers = new Set<string>();
	if (Array.isArray(parsed.workspace_members)) {
		for (const member of parsed.workspace_members) {
			if (typeof member === "string") workspaceMembers.add(member);
		}
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Run `cargo metadata --format-version 1` manually in the reported directory and fix the cargo error it prints
  2. If cargo is missing, install Rust/cargo or ensure PATH includes $CARGO_HOME/bin
  3. Verify the project root passed to discovery actually contains a valid Cargo.toml workspace
  4. Fix manifest errors (bad TOML, missing members, conflicting features) reported by cargo

Example fix

// before (broken workspace member)
// members = ["crates/missing"]
// after
# Cargo.toml
[workspace]
members = ["crates/exists"]
Defensive patterns

Strategy: try-catch

Validate before calling

const meta = Bun.spawnSync(["cargo", "metadata", "--format-version 1", "--no-deps"], { cwd: projectRoot, stderr: "pipe" });
if (meta.exitCode !== 0) throw new Error(`not a valid cargo workspace: ${meta.stderr.toString().slice(0, 200)}`);

Try / catch

try {
  const packages = await cargoWorkspacePackages(state);
  return packages;
} catch (err) {
  if (err instanceof Error && /cargo|Cargo.toml|not found/i.test(err.message)) {
    logger.warn("rust checker discovery skipped", { reason: err.message });
    return [];
  }
  throw err;
}

Prevention

When it happens

Trigger: Running the Rust checker discovery in a directory where `cargo metadata --format-version 1` fails: no Cargo.toml at the resolved root, invalid Cargo.toml/workspace manifest, cargo not on PATH (command-not-found text in stderr), or a workspace with conflicting configuration.

Common situations: Project root mis-detected (state.projectCwd/root points outside the actual workspace); a broken or hand-edited Cargo.toml; cargo/rustup not installed in the environment; workspace member listed but missing from disk.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/27dce6fe90ed85c2. Report an issue: GitHub.