{"id":"b0c16c2ba9105c8c","repo":"rust-lang/cargo","slug":"could-not-find-in-or-any-parent-director-b0c16c","errorCode":null,"errorMessage":"could not find `{}` in `{}` or any parent directory","messagePattern":"could not find `(.+?)` in `(.+?)` or any parent directory","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/important_paths.rs","lineNumber":28,"sourceCode":"\n    for current in paths::ancestors(cwd, None) {\n        let manifest = current.join(valid_cargo_toml_file_name);\n        if manifest.exists() {\n            return Ok(manifest);\n        }\n        if current.join(invalid_cargo_toml_file_name).exists() {\n            invalid_cargo_toml_path_exists = true;\n        }\n    }\n\n    if invalid_cargo_toml_path_exists {\n        anyhow::bail!(\n            \"could not find `{}` in `{}` or any parent directory, but found cargo.toml please try to rename it to Cargo.toml\",\n            valid_cargo_toml_file_name,\n            cwd.display()\n        )\n    } else {\n        anyhow::bail!(\n            \"could not find `{}` in `{}` or any parent directory\",\n            valid_cargo_toml_file_name,\n            cwd.display()\n        )\n    }\n}\n\n/// Returns the path to the `file` in `pwd`, if it exists.\npub fn find_project_manifest_exact(pwd: &Path, file: &str) -> CargoResult<PathBuf> {\n    let manifest = pwd.join(file);\n\n    if manifest.exists() {\n        Ok(manifest)\n    } else {\n        anyhow::bail!(\"Could not find `{}` in `{}`\", file, pwd.display())\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/important_paths.rs#L10-L46","documentation":"find_root_manifest_for_wd walked cwd and every ancestor directory and found no `Cargo.toml` anywhere up the tree (and no lowercase `cargo.toml` either). Cargo cannot operate outside of a package/workspace root, so it bails.","triggerScenarios":"Running any package-scoped cargo command from a directory that is not inside a Cargo project — e.g. `cargo build` run from `~`, `/tmp`, or a freshly created empty folder.","commonSituations":"Wrong working directory in a terminal/IDE; CI clone step failed so the repo is empty; running cargo before `cargo init`/`cargo new`; nested workspace where the path passed is outside the workspace root.","solutions":["`cd` into the project directory containing (or above) a Cargo.toml.","If starting fresh, run `cargo init` or `cargo new <name>` to create a project.","In CI, verify the checkout/clone succeeded and that the cwd is the repo root.","Pass `--manifest-path /abs/path/Cargo.toml` if you must run from elsewhere."],"exampleFix":"# before (run from ~)\ncargo build\n\n# after\ncd ~/projects/myapp && cargo build\n# or\ncargo build --manifest-path ~/projects/myapp/Cargo.toml","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn ensure_inside_cargo_project(cwd: &Path) -> Result<(), anyhow::Error> {\n    let found = cargo_util::paths::ancestors(cwd, None)\n        .any(|d| d.join(\"Cargo.toml\").exists());\n    if !found { anyhow::bail!(\"no Cargo.toml in {cwd:?} or ancestors; run cargo init/new or cd into the project\"); }\n    Ok(())\n}","typeGuard":"fn is_inside_cargo_project(cwd: &std::path::Path) -> bool {\n    cargo_util::paths::ancestors(cwd, None).any(|d| d.join(\"Cargo.toml\").exists())\n}","tryCatchPattern":"match find_root_manifest_for_wd(cwd) {\n    Err(e) if e.to_string().contains(\"or any parent directory\") => {\n        eprintln!(\"not inside a Cargo project; cd into one or run `cargo init`\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Confirm `pwd` before running cargo in CI/scripts.","Run `cargo init`/`cargo new` to create a project before any package command.","Pass `--manifest-path` with an absolute path when cwd is uncertain."],"tags":["filesystem","manifest","path","workspace"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}