{"record":{"id":"617f9edef4b6b245","repo":"rust-lang/cargo","slug":"manifest-is-missing-either-a-package-or-a-wo","errorCode":null,"errorMessage":"manifest is missing either a `[package]` or a `[workspace]`","messagePattern":"manifest is missing either a `\\[package\\]` or a `\\[workspace\\]`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/mod.rs","lineNumber":138,"sourceCode":"            .map(EitherManifest::Real)\n        } else if normalized_toml.workspace.is_some() {\n            assert!(!is_embedded);\n            to_virtual_manifest(\n                Some(contents),\n                Some(document),\n                original_toml,\n                normalized_toml,\n                features,\n                workspace_config,\n                source_id,\n                path,\n                gctx,\n                &mut warnings,\n                &mut errors,\n            )\n            .map(EitherManifest::Virtual)\n        } else {\n            anyhow::bail!(\"manifest is missing either a `[package]` or a `[workspace]`\")\n        }\n    })()\n    .map_err(|err| {\n        ManifestError::new(\n            err.context(format!(\"failed to parse manifest at `{}`\", path.display())),\n            path.into(),\n        )\n    })?;\n\n    for warning in warnings {\n        manifest.warnings_mut().add_warning(warning);\n    }\n    for error in errors {\n        manifest.warnings_mut().add_critical_warning(error);\n    }\n\n    Ok(manifest)\n}","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/parser/mod.rs#L120-L156","documentation":"Thrown at the top level of manifest parsing after deserialization: if the TomlManifest has neither a [package] (nor [project]) section nor a [workspace] section, it is structurally invalid. Every Cargo.toml must define at least one of these. The error is wrapped with the file path via 'failed to parse manifest at ...'.","triggerScenarios":"Calling the manifest parser on a Cargo.toml that contains only e.g. [dependencies] with no [package] or [workspace]. Also triggered by an empty file or a file with only a [lib]/[[bin]] target section.","commonSituations":"A developer creates a new Cargo.toml by hand and forgets the [package] header. A generated manifest template is incomplete. A file intended as a .cargo/config.toml is accidentally named Cargo.toml. A workspace root Cargo.toml missing the [workspace] table.","solutions":["Add a [package] section with at minimum name, version, and edition to the manifest.","If this is a virtual workspace root, add a [workspace] section with members = [...].","Verify you are pointing cargo at the correct file (not a config or lockfile)."],"exampleFix":"# before\n[dependencies]\nserde = \"1.0\"\n\n# after\n[package]\nname = \"my-crate\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\nserde = \"1.0\"","handlingStrategy":"validation","validationCode":"fn manifest_has_package_or_workspace(toml: &str) -> Result<(), String> {\n    let parsed: toml::Value = toml::from_str(toml).map_err(|e| e.to_string())?;\n    let has_pkg = parsed.get(\"package\").is_some() || parsed.get(\"project\").is_some();\n    let has_ws = parsed.get(\"workspace\").is_some();\n    if !(has_pkg || has_ws) {\n        return Err(\"manifest must contain [package] or [workspace]\".into());\n    }\n    Ok(())\n}","typeGuard":"fn is_valid_manifest_top_level(toml: &toml::Value) -> bool {\n    toml.get(\"package\").is_some() || toml.get(\"project\").is_some() || toml.get(\"workspace\").is_some()\n}","tryCatchPattern":null,"preventionTips":["Ensure every Cargo.toml has a [package] or [workspace] header before running cargo.","Use project templates that always include a [package] section.","Validate generated manifests with `cargo metadata` in CI."],"tags":["cargo","manifest","parser","missing-section","package"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}