{"record":{"id":"00d8e676e3d0c102","repo":"microsoft/aspire","slug":"cargo-metadata-failed-for-the-rust-app-resourcename-with","errorCode":null,"errorMessage":"'cargo metadata' failed for the Rust app '{resourceName}' with exit code {process.ExitCode}.{diagnosticSuffix}","messagePattern":"'cargo metadata' failed for the Rust app '(.+?)' with exit code (.+?)\\.(.+?)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/CargoMetadataReader.cs","lineNumber":127,"sourceCode":"        {\n            TryKillProcess(process);\n            throw new DistributedApplicationException(\n                $\"'cargo metadata' for the Rust app '{resourceName}' did not complete within {s_timeout.TotalSeconds:0} seconds.\");\n        }\n        catch (OperationCanceledException)\n        {\n            TryKillProcess(process);\n            throw;\n        }\n\n        var stdout = await stdoutTask.ConfigureAwait(false);\n        var stderr = await stderrTask.ConfigureAwait(false);\n\n        if (process.ExitCode != 0)\n        {\n            var diagnostic = FormatStandardError(stderr, environment, startInfo.Environment);\n            var diagnosticSuffix = diagnostic.Length > 0 ? $\" {diagnostic}\" : string.Empty;\n            throw new DistributedApplicationException(\n                $\"'cargo metadata' failed for the Rust app '{resourceName}' with exit code {process.ExitCode}.{diagnosticSuffix}\");\n        }\n\n        try\n        {\n            return CargoMetadata.Parse(stdout);\n        }\n        catch (Exception ex) when (ex is not DistributedApplicationException)\n        {\n            throw new DistributedApplicationException(\n                $\"Unable to read the output of 'cargo metadata' for the Rust app '{resourceName}'. Cargo returned invalid {ex.GetType().Name} output.\");\n        }\n    }\n\n    internal static string FormatStandardError(\n        string standardError,\n        IReadOnlyDictionary<string, string> environment,\n        IEnumerable<KeyValuePair<string, string?>>? inheritedEnvironment = null)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/CargoMetadataReader.cs#L109-L145","documentation":"After 'cargo metadata' exits with a non-zero exit code, CargoMetadataReader.ReadAsync throws DistributedApplicationException including the exit code and a diagnostic suffix built from formatted stderr. The diagnostic redacts/compares environment variables where relevant so the failure reason from cargo is surfaced.","triggerScenarios":"Running the resource whose workingDirectory has a broken Cargo.toml/workspace, missing toolchain components, unresolvable dependencies, or any condition where cargo metadata itself fails and returns non-zero.","commonSituations":"Malformed or missing Cargo.toml in the configured directory; workspace member path errors; cargo toolchain components (rustc) not installed even though cargo exists; dependency resolution failures (bad registry, missing crate version); bad .cargo/config.toml.","solutions":["Read the diagnostic suffix (cargo's stderr) in the message for the underlying cargo error and fix that first.","Run 'cargo metadata --format-version 1' manually in the resource's workingDirectory to reproduce and see the full error.","Validate Cargo.toml and workspace member paths; run 'cargo check' to confirm the workspace builds.","Ensure the full Rust toolchain (rustc, etc.) is installed via rustup, and fix any .cargo/config.toml registry settings."],"exampleFix":"// reproduce the underlying cargo failure\n// before\n$ aspire run\n# 'cargo metadata' failed for the Rust app 'api' with exit code 101. error: failed to parse manifest ...\n\n// after\n$ cd ./api && cargo metadata --format-version 1 > /dev/null\n# fix reported Cargo.toml issue (e.g. typo in dependency version), then $ aspire run","handlingStrategy":"validation","validationCode":"# Validate the workspace before running the apphost:\ncd <rust-resource-dir> && cargo metadata --format-version 1 > /dev/null && echo OK","typeGuard":null,"tryCatchPattern":"try { /* start Rust resource */ }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"with exit code\"))\n{ /* act on the embedded cargo stderr diagnostic */ }","preventionTips":["Run 'cargo check' or 'cargo metadata' in CI before the apphost to catch broken Cargo.toml early.","Keep the resource's workingDirectory pointing at the folder containing Cargo.toml.","Install the complete toolchain via rustup (rustc included), and validate .cargo/config.toml registry settings."],"tags":["rust","cargo","process-exit","build"],"backgroundTag":"command-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}