{"record":{"id":"3465ba7226aa7671","repo":"BoundaryML/baml","slug":"project-name-cannot-be-empty","errorCode":null,"errorMessage":"project name cannot be empty","messagePattern":"project name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/init_command.rs","lineNumber":170,"sourceCode":"\n/// Derive a project name from the canonical path's basename. Returns\n/// `None` if the path has no usable basename (e.g. `/`), letting the\n/// caller fall back to a hard-coded default.\nfn default_project_name(canonical: &Path) -> Option<String> {\n    canonical\n        .file_name()\n        .and_then(|s| s.to_str())\n        .filter(|s| !s.is_empty())\n        .map(|s| s.to_string())\n}\n\n/// Cargo-style project-name rules: non-empty, ASCII alphanumeric plus\n/// `-`, `_`, `.`. Whitelist beats blacklist here — `render_baml_toml`\n/// drops the name straight into a `\"...\"` TOML string, so a stray `\"`\n/// (or any control char) in the name produces an unparseable manifest.\nfn validate_project_name(name: &str) -> Result<()> {\n    if name.is_empty() {\n        anyhow::bail!(\"project name cannot be empty\");\n    }\n    let bad: Vec<char> = name\n        .chars()\n        .filter(|c| !(c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.')))\n        .collect();\n    if !bad.is_empty() {\n        anyhow::bail!(\n            \"project name `{name}` contains invalid character(s) {bad:?}. \\\n             Use ASCII letters, digits, `-`, `_`, or `.`.\"\n        );\n    }\n    Ok(())\n}\n\nfn render_baml_toml(name: &str) -> String {\n    format!(\n        r#\"[package]\nname = \"{name}\"","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/init_command.rs#L152-L188","documentation":"validate_project_name enforces Cargo-style rules before scaffolding: the name must be non-empty and consist only of ASCII alphanumerics, `-`, `_`, `.`. An empty name is rejected first. The whitelist exists because the name is embedded verbatim into a quoted TOML string in baml.toml, so stray characters would corrupt the manifest.","triggerScenarios":"Run `baml init <path> --name \"\"` (or otherwise pass an empty name) so scaffold() calls validate_project_name with an empty string.","commonSituations":"Scripted init invocations where a name variable is unset/empty and substituted as `--name \"\"`.","solutions":["Pass a non-empty name: `baml init myproj --name myproj`.","Omit `--name` and let scaffold derive the name from the path if supported.","Fix the calling script so the name variable defaults to the directory name instead of empty."],"exampleFix":"// before\nbaml init ./svc --name \"$NAME\"   // NAME empty -> bail\n// after\nbaml init ./svc --name \"${NAME:-svc}\"","handlingStrategy":"validation","validationCode":"# guard before `baml init --name \"${NAME}\"`\n[ -n \"$NAME\" ] || { echo \"project name cannot be empty\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default name variables to the directory name: ${NAME:-$(basename $PWD)}","Validate non-empty name in CI scripts","Omit --name rather than passing an empty string"],"tags":["cli","validation","project-name","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}