{"record":{"id":"8d1a06f33bd4e03a","repo":"bevyengine/bevy","slug":"failed-to-parse-cargo-manifest","errorCode":null,"errorMessage":"Failed to parse cargo manifest: {}","messagePattern":"Failed to parse cargo manifest: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_macro_utils/src/bevy_manifest.rs","lineNumber":79,"sourceCode":"                    path.display()\n                );\n                path\n            })\n            .expect(\"CARGO_MANIFEST_DIR is not defined.\")\n    }\n\n    fn get_manifest_modified_time(\n        cargo_manifest_path: &Path,\n    ) -> Result<SystemTime, std::io::Error> {\n        std::fs::metadata(cargo_manifest_path).and_then(|metadata| metadata.modified())\n    }\n\n    fn read_manifest(path: &Path) -> Document<Box<str>> {\n        let manifest = std::fs::read_to_string(path)\n            .unwrap_or_else(|_| panic!(\"Unable to read cargo manifest: {}\", path.display()))\n            .into_boxed_str();\n        Document::parse(manifest)\n            .unwrap_or_else(|_| panic!(\"Failed to parse cargo manifest: {}\", path.display()))\n    }\n\n    /// Attempt to retrieve the [path](syn::Path) of a particular package in\n    /// the [manifest](BevyManifest) by [name](str).\n    pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> {\n        // Cargo normalizes hyphens to underscores when crates are referenced from Rust code.\n        let rust_name = name.replace('-', \"_\");\n        let find_in_deps = |deps: &Item| -> Option<syn::Path> {\n            let package = if deps.get(name).is_some() {\n                return Some(Self::parse_str(&rust_name));\n            } else if deps.get(BEVY).is_some() {\n                BEVY\n            } else {\n                // Note: to support bevy crate aliases, we could do scanning here to find a crate with a \"package\" name that\n                // matches our request, but that would then mean we are scanning every dependency (and dev dependency) for every\n                // macro execution that hits this branch (which includes all built-in bevy crates). Our current stance is that supporting\n                // remapped crate names in derive macros is not worth that \"compile time\" price of admission. As a workaround, people aliasing\n                // bevy crate names can use \"use REMAPPED as bevy_X\" or \"use REMAPPED::x as bevy_x\".","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_macro_utils/src/bevy_manifest.rs#L61-L97","documentation":"This panic is raised inside Bevy's proc-macro support code when a derive macro (any bevy derive that resolves crate paths via BevyManifest) tries to read and parse the workspace Cargo.toml and the TOML parser fails. The manifest is read at compile time during macro expansion, so a malformed Cargo.toml turns into a hard build failure with this message. The sibling panic 'Unable to read cargo manifest' covers I/O failures, while this one means the file was read but is not parseable TOML.","triggerScenarios":"Any bevy derive macro (e.g. #[derive(Component)], #[derive(Bundle)], #[derive(Resource)]) expanding in a crate whose Cargo.toml contains invalid TOML syntax — unbalanced brackets, merge-conflict markers (<<<<<<<), duplicate table headers, or non-UTF-8 bytes. Also triggered when rust-analyzer or an out-of-sync build reads a partially-saved/hand-edited manifest.","commonSituations":"Git merge conflicts left in Cargo.toml; manual edits that break TOML syntax; BOM or encoding issues; editors writing the file mid-save while cargo check runs; rare cases where cargo tolerates the file but toml_edit's stricter parse rejects it after a toolchain or bevy version bump.","solutions":["Run `cargo metadata --format-version 1 --no-deps` — if it errors, the TOML syntax error (with line/column) is reported; fix that spot in Cargo.toml.","Search Cargo.toml for merge-conflict markers (<<<<<<<, =======, >>>>>>>) and resolve them.","Verify the file is valid UTF-8 without BOM (`file Cargo.toml` or `iconv -f utf-8 -t utf-8 Cargo.toml -o /dev/null`).","If an external tool generates the manifest, regenerate it and confirm the produced TOML with a linter (e.g. `taplo check` or `toml` parse in a scratch script)."],"exampleFix":"# before (Cargo.toml — broken after a merge)\n[dependencies\nbevy = \"0.14\"\n<<<<<<< HEAD\nbevy_math = \"0.14\"\n=======\nbevy_transform = \"0.14\"\n>>>>>>>\n\n# after\n[dependencies]\nbevy = \"0.14\"\nbevy_math = \"0.14\"","handlingStrategy":"validation","validationCode":"# CI gate (shell) — fails fast with a precise TOML error before any bevy macro runs:\ncargo metadata --format-version 1 --no-deps > /dev/null || echo \"Cargo.toml is not valid TOML\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `cargo metadata --no-deps` (or `cargo check`) in CI before build jobs so TOML errors surface with line/column instead of a proc-macro panic.","Resolve merge conflicts in Cargo.toml immediately; grep the diff for '<<<<<<<' before committing.","Prefer `cargo add` over hand-editing dependencies sections.","Keep Cargo.toml UTF-8 without BOM."],"tags":["rust","bevy","proc-macro","toml","compile-time","cargo-manifest"],"backgroundTag":"toml-parse-error","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}