{"record":{"id":"d75919dc88f421ba","repo":"gastownhall/beads","slug":"failed-to-search-for-existing-databases-w","errorCode":null,"errorMessage":"failed to search for existing databases: %w","messagePattern":"failed to search for existing databases: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":2377,"sourceCode":"func migrateOldDatabases(targetPath string, quiet bool) error {\n\ttargetDir := filepath.Dir(targetPath)\n\ttargetName := filepath.Base(targetPath)\n\n\t// If target already exists, no migration needed\n\tif _, err := os.Stat(targetPath); err == nil {\n\t\treturn nil\n\t}\n\n\t// Create .beads directory if it doesn't exist\n\tif err := os.MkdirAll(targetDir, 0750); err != nil {\n\t\treturn fmt.Errorf(\"failed to create .beads directory: %w\", err)\n\t}\n\n\t// Look for existing .db files in the .beads directory\n\tpattern := filepath.Join(targetDir, \"*.db\")\n\tmatches, err := filepath.Glob(pattern)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to search for existing databases: %w\", err)\n\t}\n\n\t// Filter out the target file name and any backup files\n\tvar oldDBs []string\n\tfor _, match := range matches {\n\t\tbaseName := filepath.Base(match)\n\t\tif baseName != targetName && !strings.HasSuffix(baseName, \".backup.db\") {\n\t\t\toldDBs = append(oldDBs, match)\n\t\t}\n\t}\n\n\tif len(oldDBs) == 0 {\n\t\t// No old databases to migrate\n\t\treturn nil\n\t}\n\n\tif len(oldDBs) > 1 {\n\t\t// Multiple databases found - ambiguous, require manual intervention","sourceCodeStart":2359,"sourceCodeEnd":2395,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L2359-L2395","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nexport BEADS_DIR='/weird[path with [brackets'\nbd init  # failed to search for existing databases: syntax error in pattern\n\n// after\nexport BEADS_DIR='/home/me/project/.beads'\nbd init","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(beadsDir, \"[]*\") {\n    return fmt.Errorf(\"BEADS_DIR %q contains glob metacharacters; use a plain path\", beadsDir)\n}","typeGuard":null,"tryCatchPattern":"if err := migrateOldDatabases(targetPath, quiet); err != nil && strings.Contains(err.Error(), \"failed to search for existing databases\") {\n    // glob pattern malformed: log the resolved dir and abort with a config hint\n    return fmt.Errorf(\"check BEADS_DIR for invalid characters: %w\", err)\n}","preventionTips":["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."],"tags":["filesystem","glob","init","go"],"backgroundTag":"bad-glob-pattern","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}