{"id":"3efbb459fb3d482a","repo":"rust-lang/cargo","slug":"manifest-path-is-a-directory-but-expected-a-f","errorCode":null,"errorMessage":"manifest path `{}` is a directory but expected a file{suggested_path}","messagePattern":"manifest path `(.+?)` is a directory but expected a file(.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":1064,"sourceCode":"    args._values_of_os(name)\n}\n\npub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> CargoResult<PathBuf> {\n    if let Some(manifest_path) = manifest_path {\n        let path = gctx.cwd().join(manifest_path);\n        // In general, we try to avoid normalizing paths in Cargo,\n        // but in this particular case we need it to fix #3586.\n        let path = paths::normalize_path(&path);\n        if !path.exists() {\n            anyhow::bail!(\"manifest path `{}` does not exist\", manifest_path.display())\n        } else if path.is_dir() {\n            let child_path = path.join(\"Cargo.toml\");\n            let suggested_path = if child_path.exists() {\n                format!(\"\\nhelp: {} exists\", child_path.display())\n            } else {\n                \"\".to_string()\n            };\n            anyhow::bail!(\n                \"manifest path `{}` is a directory but expected a file{suggested_path}\",\n                manifest_path.display()\n            )\n        } else if !path.ends_with(\"Cargo.toml\") && !crate::workspace::parser::is_embedded(&path) {\n            if gctx.cli_unstable().script {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml or script file: `{}`\",\n                    path.display()\n                )\n            } else {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml file: `{}`\",\n                    path.display()\n                )\n            }\n        }\n        if crate::workspace::parser::is_embedded(&path) && !gctx.cli_unstable().script {\n            anyhow::bail!(\"embedded manifest `{}` requires `-Zscript`\", path.display())","sourceCodeStart":1046,"sourceCodeEnd":1082,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L1046-L1082","documentation":"root_manifest checks that `--manifest-path` exists and is NOT a directory. If the path is a directory, Cargo bails and, when a `Cargo.toml` child exists inside it, appends a help line suggesting that file. Cargo expects a file path, not a folder.","triggerScenarios":"Passing a directory to `--manifest-path`: `cargo build --manifest-path ./mycrate` where `mycrate/` is a folder (commonly one that contains a Cargo.toml).","commonSituations":"Pointing `--manifest-path` at the crate directory rather than its Cargo.toml; muscle memory from tools that accept a directory; scripts that pass `${PROJECT_DIR}` instead of `${PROJECT_DIR}/Cargo.toml`.","solutions":["Append `Cargo.toml`: `cargo build --manifest-path ./mycrate/Cargo.toml`.","If the help line suggests a path, use exactly that path.","Drop `--manifest-path` and `cd` into the directory so Cargo auto-discovers Cargo.toml."],"exampleFix":"# before\ncargo build --manifest-path ./mycrate\n\n# after\ncargo build --manifest-path ./mycrate/Cargo.toml","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn ensure_manifest_is_file(p: &Path) -> Result<(), anyhow::Error> {\n    if !p.exists() { anyhow::bail!(\"{p:?} missing\"); }\n    if p.is_dir() { anyhow::bail!(\"{p:?} is a directory; append Cargo.toml\"); }\n    Ok(())\n}","typeGuard":"fn is_manifest_file(p: &std::path::Path) -> bool {\n    p.is_file() && p.file_name().map(|n| n == \"Cargo.toml\").unwrap_or(false)\n}","tryCatchPattern":"match root_manifest(Some(path), gctx) {\n    Err(e) if e.to_string().contains(\"is a directory\") => {\n        eprintln!(\"pass the Cargo.toml file, not its directory\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Always append `Cargo.toml` when the path is a directory.","Watch for IDE auto-complete completing to the folder."],"tags":["cli","manifest","filesystem","path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}