{"id":"6b9c7b0d9f10091f","repo":"rust-lang/cargo","slug":"err-help","errorCode":null,"errorMessage":"{err}{help}","messagePattern":"\\{err\\}\\{help\\}","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":206,"sourceCode":"            help.push_str(&format!(\n                \"\\n\\\n                help: to name the binary \\\"{name}\\\", use a valid package \\\n                name, and set the binary name to be different from the package. \\\n                This can be done by setting the binary filename to `src/bin/{name}.rs` \\\n                or change the name in Cargo.toml with:\\n\\\n                \\n    \\\n                [[bin]]\\n    \\\n                name = \\\"{name}\\\"\\n    \\\n                path = \\\"src/main.rs\\\"\\n\\\n            \",\n                name = name\n            ));\n        }\n        help\n    };\n    PackageName::new(name).map_err(|err| {\n        let help = bin_help();\n        anyhow::anyhow!(\"{err}{help}\")\n    })?;\n\n    if restricted_names::is_keyword(name) {\n        anyhow::bail!(\n            \"invalid package name `{}`: it is a Rust keyword{}\",\n            name,\n            bin_help()\n        );\n    }\n    if restricted_names::is_conflicting_artifact_name(name) {\n        if has_bin {\n            anyhow::bail!(\n                \"invalid package name `{}`: \\\n                it conflicts with cargo's build directory names{}\",\n                name,\n                name_help\n            );\n        } else {","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_new.rs#L188-L224","documentation":"Generic wrapper around the structured validation performed by PackageName::new (from cargo_util_schemas). It fires when the chosen package name violates core crate-name rules: empty name, leading digit, invalid characters (anything beyond ASCII alphanumerics, '-', '_'), exceeding the 64-character length cap, or a reserved form. The appended {help} text provides context-aware suggestions (e.g. how to set a [[bin]] name with a different package name).","triggerScenarios":"`cargo new 1app`, `cargo new my.app`, `cargo new \"\"`, `cargo new` in a directory whose name is too long (>64 chars), or `--name` with disallowed symbols. The error originates from PackageName::new(name) at cargo_new.rs:204.","commonSituations":"Naming a crate after a directory like `My App` (space), `2fa-helper` (leading digit), or a very long path component. Using CamelCase or dots because the project directory was created by another tool. Confusing package name rules with module name rules.","solutions":["Rename to use only ASCII letters, digits, hyphens, underscores, starting with a letter, <=64 chars","Pass `--name <valid>` to override the auto-detected directory name","If the invalid directory name is the cause, `mv` the directory first","Read the appended help line; it often suggests the exact [[bin]] block to add so the binary name can differ from the package name"],"exampleFix":"# before\ncargo new \"My App\"\n# after\ncargo new my-app\n# or keep dir, override name:\ncargo new \"My App\" --name my-app","handlingStrategy":"validation","validationCode":"// Mirror cargo_util_schemas::manifest::PackageName rules\nfn valid_pkg_name(name: &str) -> bool {\n    !name.is_empty()\n        && name.len() <= 64\n        && name.chars().next().map_or(false, |c| c.is_ascii_alphabetic())\n        && name.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')\n}\n\nif !valid_pkg_name(name) { /* fail early with a friendly message */ }","typeGuard":"const PKG_NAME_RE = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;\nfunction isValidPackageName(name: string): boolean {\n  return PKG_NAME_RE.test(name);\n}","tryCatchPattern":null,"preventionTips":["Validate names with a regex mirroring PackageName::new before invoking cargo","Derive crate names from a constrained allow-list in generators/templates","Add a CI lint that rejects Cargo.toml [package].name outside the allowed pattern"],"tags":["cargo-new","package-name","validation","naming"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}