{"id":"bbc2398f0f155e72","repo":"rust-lang/cargo","slug":"error","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/tree.rs","lineNumber":158,"sourceCode":"pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {\n    if args.flag(\"version\") {\n        let verbose = args.verbose() > 0;\n        let version = cli::get_version_string(verbose);\n        cargo::drop_print!(gctx, \"{}\", version);\n        return Ok(());\n    }\n    let prefix = if args.flag(\"no-indent\") {\n        gctx.shell()\n            .warn(\"the --no-indent flag has been changed to --prefix=none\")?;\n        \"none\"\n    } else if args.flag(\"prefix-depth\") {\n        gctx.shell()\n            .warn(\"the --prefix-depth flag has been changed to --prefix=depth\")?;\n        \"depth\"\n    } else {\n        args.get_one::<String>(\"prefix\").unwrap().as_str()\n    };\n    let prefix = cargo_tree::Prefix::from_str(prefix).map_err(|e| anyhow::anyhow!(\"{}\", e))?;\n\n    let no_dedupe = args.flag(\"no-dedupe\") || args.flag(\"all\");\n    if args.flag(\"all\") {\n        gctx.shell().print_report(\n            &[Level::WARNING\n                .secondary_title(\n                    \"the `cargo tree` --all flag has been changed to --no-dedupe, \\\n                    and may be removed in a future version\",\n                )\n                .element(Level::HELP.message(\n                    \"if you are looking to display all workspace members, use the --workspace flag\",\n                ))],\n            false,\n        )?;\n    }\n\n    let targets = if args.flag(\"all-targets\") {\n        gctx.shell()","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/tree.rs#L140-L176","documentation":"In `cargo tree`'s exec (tree.rs:158), the `--prefix` value is parsed via `cargo_tree::Prefix::from_str`. An unrecognized prefix string produces a static error message that is wrapped with `anyhow::anyhow!(\"{}\", e)` and returned. The valid prefix values are typically `none`, `depth`, and indent-style prefixes defined by the `cargo_tree` crate.","triggerScenarios":"Passing `cargo tree --prefix=foo` where `foo` is not one of the accepted prefix values (`none`, `depth`, or the default indentation variants).","commonSituations":"Misspelling `--prefix=depth` or `--prefix=none`; passing a value carried over from a different tool's docs; using a value only valid in a newer/older cargo-tree.","solutions":["Use a valid `--prefix` value: `none` or `depth` (or omit the flag for the default).","Run `cargo tree --help` to see accepted values for your Cargo version.","If you relied on legacy behavior, note `--no-indent` maps to `--prefix=none` and `--prefix-depth` maps to `--prefix=depth`."],"exampleFix":"// before\n$ cargo tree --prefix=compact\nerror: invalid prefix\n\n// after\n$ cargo tree --prefix=none","handlingStrategy":"validation","validationCode":"let valid_prefixes = [\"none\", \"depth\"]; // per cargo-tree::Prefix\nif !valid_prefixes.contains(&prefix.as_str()) {\n    return Err(format!(\"invalid --prefix `{prefix}`; expected one of {valid_prefixes:?}\"));\n}","typeGuard":"fn is_valid_prefix(p: &str) -> bool {\n    matches!(p, \"none\" | \"depth\")\n}\n","tryCatchPattern":null,"preventionTips":["Validate --prefix against the documented set before invoking cargo tree.","Wrap cargo invocations in code that checks flag values against `cargo tree --help`."],"tags":["cargo","tree","cli","argument"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}