benbjohnson/litestream · error

database not found: %s

Error message

database not found: %s

What it means

EnableDB looks up a registered database by path before starting replication; if no DB with that exact path is registered in the Store, it returns this error. It is a lookup failure, not a filesystem check — the DB must have been registered (via config load or RegisterDB) first.

Source

Thrown at store.go:384

	}

	s.dbs = slices.Delete(s.dbs, idx, idx+1)
	s.mu.Unlock()

	if err := db.Close(ctx); err != nil {
		return fmt.Errorf("close db: %w", err)
	}

	return nil
}

// EnableDB starts replication for a registered database.
// The context is checked for cancellation before opening.
// Note: db.Open() itself does not support cancellation.
func (s *Store) EnableDB(ctx context.Context, path string) error {
	db := s.FindDB(path)
	if db == nil {
		return fmt.Errorf("database not found: %s", path)
	}

	if db.IsOpen() {
		return fmt.Errorf("database already enabled: %s", path)
	}

	// Check for cancellation before starting open
	if err := ctx.Err(); err != nil {
		return fmt.Errorf("enable database: %w", err)
	}

	if err := db.Open(); err != nil {
		return fmt.Errorf("open database: %w", err)
	}

	return nil
}

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Call Store.FindDB(path) first and confirm it is non-nil with the exact path
  2. Use the absolute, cleaned path exactly as it appears in the litestream config (filepath.Abs + filepath.Clean)
  3. List registered DBs (e.g. via IPC) and match the path string before enabling
  4. Register the database first if it is genuinely missing from the store

Example fix

// before
err := store.EnableDB(ctx, "data/app.db") // relative path not registered
// after
abs, _ := filepath.Abs("data/app.db")
if store.FindDB(abs) == nil {
    return fmt.Errorf("db not registered: %s", abs)
}
err := store.EnableDB(ctx, abs)
Defensive patterns

Strategy: validation

Validate before calling

abs, err := filepath.Abs(path)
if err != nil { return err }
if store.FindDB(abs) == nil {
    return fmt.Errorf("db not registered: %s", abs)
}

Try / catch

if err := store.EnableDB(ctx, abs); err != nil {
    if strings.Contains(err.Error(), "database not found") {
        // list registered DBs and surface correct path
    }
    return err
}

Prevention

When it happens

Trigger: Store.EnableDB(ctx, path) (via IPC handleStart) with a path that is not registered: typo in path, relative vs absolute path mismatch, or DB never registered / already unregistered.

Common situations: Sending a 'start' IPC command with a path that differs from the configured path (symlinks, relative paths, trailing slash); calling EnableDB before config registration completes; DB was removed by a concurrent unregister.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/dd13f4055e2b377f. Report an issue: GitHub.