BoundaryML/baml · error
project name cannot be empty
Error message
project name cannot be empty
What it means
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.
Source
Thrown at baml_language/crates/baml_cli/src/init_command.rs:170
/// Derive a project name from the canonical path's basename. Returns
/// `None` if the path has no usable basename (e.g. `/`), letting the
/// caller fall back to a hard-coded default.
fn default_project_name(canonical: &Path) -> Option<String> {
canonical
.file_name()
.and_then(|s| s.to_str())
.filter(|s| !s.is_empty())
.map(|s| s.to_string())
}
/// Cargo-style project-name rules: non-empty, ASCII alphanumeric plus
/// `-`, `_`, `.`. Whitelist beats blacklist here — `render_baml_toml`
/// drops the name straight into a `"..."` TOML string, so a stray `"`
/// (or any control char) in the name produces an unparseable manifest.
fn validate_project_name(name: &str) -> Result<()> {
if name.is_empty() {
anyhow::bail!("project name cannot be empty");
}
let bad: Vec<char> = name
.chars()
.filter(|c| !(c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.')))
.collect();
if !bad.is_empty() {
anyhow::bail!(
"project name `{name}` contains invalid character(s) {bad:?}. \
Use ASCII letters, digits, `-`, `_`, or `.`."
);
}
Ok(())
}
fn render_baml_toml(name: &str) -> String {
format!(
r#"[package]
name = "{name}"View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before
baml init ./svc --name "$NAME" // NAME empty -> bail
// after
baml init ./svc --name "${NAME:-svc}" Defensive patterns
Strategy: validation
Validate before calling
# guard before `baml init --name "${NAME}"`
[ -n "$NAME" ] || { echo "project name cannot be empty"; exit 1; } Prevention
- 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
When it happens
Trigger: Run `baml init <path> --name ""` (or otherwise pass an empty name) so scaffold() calls validate_project_name with an empty string.
Common situations: Scripted init invocations where a name variable is unset/empty and substituted as `--name ""`.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- project name `{name}` contains invalid character(s) {bad:?}.
- unknown feedback field(s) {}; only "title" and "description"
- feedback field "{key}" must be a string
- feedback needs a title; pass --title "..." or a JSON payload
- feedback payload must be a JSON object like {"title": "..."}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/3465ba7226aa7671.
Report an issue: GitHub.