gastownhall/beads · error
database name cannot be empty
Error message
database name cannot be empty
What it means
ValidateDatabaseName rejects an empty database name before it can be interpolated into SQL. It is the first of several checks (empty, >64 chars, pattern match) guarding against SQL injection via backtick escaping in CREATE DATABASE / query construction.
Source
Thrown at internal/storage/dolt/history.go:31
)
// validTablePattern matches valid table names
var validTablePattern = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
// validDatabasePattern matches valid MySQL database names (alphanumeric, underscore, hyphen)
var validDatabasePattern = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_\-]*$`)
// validateRef checks if a ref is safe to use in queries.
// Delegates to issueops.ValidateRef.
func validateRef(ref string) error {
return issueops.ValidateRef(ref)
}
// ValidateDatabaseName checks if a database name is safe to use in queries.
// Prevents SQL injection via backtick escaping in CREATE DATABASE statements.
func ValidateDatabaseName(name string) error {
if name == "" {
return fmt.Errorf("database name cannot be empty")
}
if len(name) > 64 {
return fmt.Errorf("database name too long")
}
if !validDatabasePattern.MatchString(name) {
return fmt.Errorf("invalid database name: %s", name)
}
return nil
}
// validateTableName checks if a table name is safe to use in queries
func validateTableName(table string) error {
if table == "" {
return fmt.Errorf("table name cannot be empty")
}
if len(table) > 64 {
return fmt.Errorf("table name too long")
}View on GitHub (pinned to 71377f2769)
Solutions
- Set the database name in config or via the environment variable before calling the API
- Add an early check/flag default so an empty name is replaced with the intended database
- If derived from a remote URL, verify the URL includes the database path segment
- Run ValidateDatabaseName yourself at config-load time to fail fast with a clear message
Example fix
// before
store, err := BootstrapFromRemoteWithRemote(ctx, remoteURL, "") // empty DB
// after
dbName := os.Getenv("BEADS_DB")
if err := dolt.ValidateDatabaseName(dbName); err != nil {
return fmt.Errorf("configure a database name: %w", err)
}
store, err := BootstrapFromRemoteWithRemote(ctx, remoteURL, dbName) Defensive patterns
Strategy: validation
Validate before calling
func requireDBName(name string) error {
if strings.TrimSpace(name) == "" {
return errors.New("database name must be set (check config / env)")
}
return nil
}
if err := requireDBName(cfg.Database); err != nil { return err } Type guard
func hasDatabaseName(name string) bool { return strings.TrimSpace(name) != "" } Try / catch
if err := dolt.ValidateDatabaseName(name); err != nil {
switch {
case err.Error() == "database name cannot be empty": // fix config
case strings.Contains(err.Error(), "too long"): // truncate/choose shorter name
default: // invalid chars, sanitize
}
} Prevention
- Validate DB name at config load with ValidateDatabaseName
- Distinguish unset vs empty env vars when defaulting
- Derive DB names from URLs only after verifying the path segment exists
When it happens
Trigger: BootstrapFromRemoteWithDB, openServerConnection, or other callers pass an empty string as the database name — typically an unset config field or an empty env var (e.g. BEADS_DB unset).
Common situations: Config struct field never populated; environment variable empty rather than unset so the default isn't applied; CLI flag provided as empty string; remote URL parsed without a database component.
Related errors
- ExternalDoltConfig: Port %d out of range [1, 65535]
- uow: doltBinExec must not be empty
- uow: database name must not be empty (caller should default
- uow: rootUser must not be empty
- uow: external: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/07be51b8512244e1.
Report an issue: GitHub.