{"record":{"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":null,"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/util/important_paths.rs#L10-L46","documentation":"find_root_manifest_for_wd found neither Cargo.toml nor cargo.toml in cwd or any ancestor. Cargo is therefore not running inside any package/workspace root.","triggerScenarios":"Invoking a package-scoped cargo subcommand (build, run, test, etc.) from a directory that is not inside a Cargo project.","commonSituations":"Wrong shell cwd; running cargo in a freshly cloned empty repo before adding a manifest; running from /tmp or home dir.","solutions":["cd into the project directory containing Cargo.toml.","Pass --manifest-path to point at an existing Cargo.toml.","Create a new project with `cargo new` / `cargo init` if none exists."],"exampleFix":"# before\n# cd /tmp && cargo build\n\n# after\n# cd ~/projects/myapp && cargo build\n# or: cargo build --manifest-path ~/projects/myapp/Cargo.toml","handlingStrategy":"validation","validationCode":"use std::path::Path;\n\nfn ensure_in_cargo_project(cwd: &Path) -> Result<PathBuf, String> {\n    for dir in paths::ancestors(cwd, None) {\n        let m = dir.join(\"Cargo.toml\");\n        if m.is_file() { return Ok(m); }\n    }\n    Err(format!(\"no Cargo.toml in {cwd:?} or any parent; cd into the project or run `cargo new`\"))\n}","typeGuard":"fn is_inside_cargo_project(cwd: &std::path::Path) -> bool {\n    paths::ancestors(cwd, None).any(|d| d.join(\"Cargo.toml\").is_file())\n}","tryCatchPattern":null,"preventionTips":["Confirm cwd before invoking cargo; print `pwd` in CI logs.","Use --manifest-path to make resolution explicit in scripts.","Run `cargo new`/`cargo init` if no project exists yet."],"tags":["manifest","paths","workspace"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}