{"record":{"id":"27dce6fe90ed85c2","repo":"can1357/oh-my-pi","slug":"result-stderr-result-stdout-replace-s-g","errorCode":null,"errorMessage":"${(result.stderr || result.stdout).replace(/\\s+/g, \" \").trim()}","messagePattern":"\\$\\{\\(result\\.stderr \\|\\| result\\.stdout\\)\\.replace\\(/\\\\s\\+/g, \" \"\\)\\.trim\\(\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cleanse/checkers.ts","lineNumber":490,"sourceCode":"\t\t\t\targs: [\"test\", \"--no-fail-fast\", \"--all-targets\", ...packageArgs, \"--message-format=json\"],\n\t\t\t\tparser: \"rust-test\",\n\t\t\t});\n\t\t}\n\t}\n}\n\nasync function cargoWorkspacePackages(state: DiscoveryState, root: string, cargo: string): Promise<string[]> {\n\tconst manifest = path.resolve(state.projectCwd, root, \"Cargo.toml\");\n\tconst result = await ptree.exec(\n\t\t[cargo, \"metadata\", \"--no-deps\", \"--format-version=1\", \"--manifest-path\", manifest],\n\t\t{\n\t\t\tcwd: path.resolve(state.projectCwd, root),\n\t\t\tstderr: \"full\",\n\t\t\tallowNonZero: true,\n\t\t},\n\t);\n\tif (!result.ok) {\n\t\tthrow new Error(\n\t\t\tsanitizeText(result.stderr || result.stdout)\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim(),\n\t\t);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(result.stdout);\n\t} catch (error) {\n\t\tthrow new Error(`invalid JSON: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (!isRecord(parsed)) throw new Error(\"metadata root is not an object\");\n\tconst workspaceMembers = new Set<string>();\n\tif (Array.isArray(parsed.workspace_members)) {\n\t\tfor (const member of parsed.workspace_members) {\n\t\t\tif (typeof member === \"string\") workspaceMembers.add(member);\n\t\t}\n\t}","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cleanse/checkers.ts#L472-L508","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `cargo metadata --format-version 1` manually in the reported directory and fix the cargo error it prints","If cargo is missing, install Rust/cargo or ensure PATH includes $CARGO_HOME/bin","Verify the project root passed to discovery actually contains a valid Cargo.toml workspace","Fix manifest errors (bad TOML, missing members, conflicting features) reported by cargo"],"exampleFix":"// before (broken workspace member)\n// members = [\"crates/missing\"]\n// after\n# Cargo.toml\n[workspace]\nmembers = [\"crates/exists\"]","handlingStrategy":"try-catch","validationCode":"const meta = Bun.spawnSync([\"cargo\", \"metadata\", \"--format-version 1\", \"--no-deps\"], { cwd: projectRoot, stderr: \"pipe\" });\nif (meta.exitCode !== 0) throw new Error(`not a valid cargo workspace: ${meta.stderr.toString().slice(0, 200)}`);","typeGuard":null,"tryCatchPattern":"try {\n  const packages = await cargoWorkspacePackages(state);\n  return packages;\n} catch (err) {\n  if (err instanceof Error && /cargo|Cargo.toml|not found/i.test(err.message)) {\n    logger.warn(\"rust checker discovery skipped\", { reason: err.message });\n    return [];\n  }\n  throw err;\n}","preventionTips":["Ensure cargo is installed and on PATH in all environments (CI containers included)","Validate the workspace builds (cargo check) before running cleanse discovery","Confirm project root detection points at the directory containing Cargo.toml","Keep workspace manifests valid; run cargo metadata locally after manifest edits"],"tags":["rust","cargo","subprocess"],"backgroundTag":"cargo-command-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}