gastownhall/beads · error

invalid database name

Error message

invalid database name: %s

What it means

ValidateDatabaseName rejects names that do not match validDatabasePattern (safe identifier characters). This is an injection guard: database names are interpolated into backtick-quoted CREATE DATABASE statements, and characters that could break out of backtick escaping are disallowed. The offending name is included in the message.

Solutions

  1. Sanitize the database name to match the allowed identifier pattern (alphanumerics/underscores, no backticks, quotes, spaces or path separators).
  2. If the name comes from a repo slug, replace '/' and other separators with '_' before calling bootstrap/connect.
  3. Trim whitespace from configuration/env-sourced values; re-read the config to confirm the intended short name is used, not a URL.

Example fix

// before
dbName := strings.TrimPrefix(remote, "https://doltremoteapi.dolthub.com/") // "org/repo"
store, err := dolt.BootstrapFromRemoteWithDB(ctx, remote, dbName)
// after
dbName := strings.ReplaceAll(strings.TrimPrefix(remote, "https://doltremoteapi.dolthub.com/"), "/", "_") // "org_repo"
store, err := dolt.BootstrapFromRemoteWithDB(ctx, remote, dbName)
Defensive patterns

Strategy: validation

Validate before calling

var dbPattern = regexp.MustCompile(`^[A-Za-z0-9_]+$`)
func validDBName(name string) bool { return dbPattern.MatchString(name) }
if !validDBName(dbName) { return fmt.Errorf("db name %q contains invalid characters", dbName) }

Prevention

When it happens

Trigger: Passing BootstrapFromRemoteWithDB or openServerConnection a database name containing characters outside the allowed identifier set — e.g. backticks, quotes, spaces, slashes, hyphens in positions the pattern rejects, or non-ASCII characters.

Common situations: Using an org/repo string like 'myorg/myrepo' or 'my repo' as a database name; names with URL-encoded characters or trailing whitespace from config files; programmatic name generation inserting separators like ':' or '#'.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/559a1c09d2d99fb0. Report an issue: GitHub.

Appendix: source

Thrown at internal/storage/dolt/history.go:37

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")
	}
	if !validTablePattern.MatchString(table) {
		return fmt.Errorf("invalid table name: %s", table)
	}
	return nil
}

View on GitHub (pinned to 71377f2769)