gastownhall/beads · error
failed to search for existing databases: %w
Error message
failed to search for existing databases: %w
What it means
migrateOldDatabases globs `<beads-dir>/*.db` to find legacy database files that should be renamed to the canonical beads.db. This error wraps a filepath.Glob failure. It is rare: Glob only errors on malformed patterns (ErrBadPattern), so it usually indicates an internal/configuration problem with the target path rather than an environment issue.
Source
Thrown at cmd/bd/init.go:2377
func migrateOldDatabases(targetPath string, quiet bool) error {
targetDir := filepath.Dir(targetPath)
targetName := filepath.Base(targetPath)
// If target already exists, no migration needed
if _, err := os.Stat(targetPath); err == nil {
return nil
}
// Create .beads directory if it doesn't exist
if err := os.MkdirAll(targetDir, 0750); err != nil {
return fmt.Errorf("failed to create .beads directory: %w", err)
}
// Look for existing .db files in the .beads directory
pattern := filepath.Join(targetDir, "*.db")
matches, err := filepath.Glob(pattern)
if err != nil {
return fmt.Errorf("failed to search for existing databases: %w", err)
}
// Filter out the target file name and any backup files
var oldDBs []string
for _, match := range matches {
baseName := filepath.Base(match)
if baseName != targetName && !strings.HasSuffix(baseName, ".backup.db") {
oldDBs = append(oldDBs, match)
}
}
if len(oldDBs) == 0 {
// No old databases to migrate
return nil
}
if len(oldDBs) > 1 {
// Multiple databases found - ambiguous, require manual interventionView on GitHub (pinned to 71377f2769)
Solutions
- Inspect the resolved .beads directory path (echo $BEADS_DIR) for malformed characters and correct it.
- Re-run bd init; the error is usually transient/config-derived since the "*.db" pattern is fixed.
- If reproducible with a plain path, report it as a bug with the exact targetDir value.
Example fix
// before export BEADS_DIR='/weird[path with [brackets' bd init # failed to search for existing databases: syntax error in pattern // after export BEADS_DIR='/home/me/project/.beads' bd init
Defensive patterns
Strategy: validation
Validate before calling
if strings.ContainsAny(beadsDir, "[]*") {
return fmt.Errorf("BEADS_DIR %q contains glob metacharacters; use a plain path", beadsDir)
} Try / catch
if err := migrateOldDatabases(targetPath, quiet); err != nil && strings.Contains(err.Error(), "failed to search for existing databases") {
// glob pattern malformed: log the resolved dir and abort with a config hint
return fmt.Errorf("check BEADS_DIR for invalid characters: %w", err)
} Prevention
- Keep BEADS_DIR free of glob metacharacters ([, ], *).
- Always set BEADS_DIR to an absolute, plain filesystem path.
- Quote paths in shell profiles to avoid stray characters leaking into env vars.
When it happens
Trigger: Running `bd init` when filepath.Glob(filepath.Join(targetDir, "*.db")) returns a non-nil error — in practice only when the joined pattern is malformed (e.g. a targetDir containing an invalid glob character sequence on platforms that enforce ErrBadPattern).
Common situations: BEADS_DIR or target path containing unusual characters that corrupt the glob pattern; a bug in path construction upstream; almost never hit by ordinary users since "*.db" is itself a valid pattern.
Related errors
- failed to create .beads directory: %w
- dolt path is not executable
- server: NewDoltServer: failed to determine absolute path of
- server: NewDoltServer: failed to determine absolute path of
- server: NewDoltServer: failed to determine absolute path of
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/d75919dc88f421ba.
Report an issue: GitHub.