gastownhall/beads · error

no store available

Error message

no store available

What it means

getFederatedStore returns the process-global `store` used by federation subcommands, and this error means that global was never initialized. In bd, the global store is set up by root command initialization (persistent pre-run) when a database is opened; if federation sync/status runs before that setup — or in a mode that skips store creation — there is no storage handle to operate on.

Source

Thrown at cmd/bd/federation.go:145

	// Flags for sync
	federationSyncCmd.Flags().StringVar(&federationPeer, "peer", "", "Specific peer to sync with")
	federationSyncCmd.Flags().StringVar(&federationStrategy, "strategy", "", "Conflict resolution strategy (ours|theirs)")

	// Flags for status
	federationStatusCmd.Flags().StringVar(&federationPeer, "peer", "", "Specific peer to check")

	// Flags for add-peer (SQL user authentication)
	federationAddPeerCmd.Flags().StringVarP(&federationUser, "user", "u", "", "SQL username for authentication")
	federationAddPeerCmd.Flags().StringVarP(&federationPassword, "password", "p", "", "SQL password (prompted if --user set without --password)")
	federationAddPeerCmd.Flags().StringVar(&federationSov, "sovereignty", "", "Sovereignty tier (T1, T2, T3, T4)")

	rootCmd.AddCommand(federationCmd)
}

func getFederatedStore() (storage.DoltStorage, error) {
	if store == nil {
		return nil, fmt.Errorf("no store available")
	}
	return store, nil
}

func runFederationSync(cmd *cobra.Command, args []string) error {
	if usesProxiedServer() {
		return HandleErrorRespectJSON("federation sync is not supported in proxied-server mode")
	}
	evt := metrics.NewCommandEvent("federation-sync")
	defer func() {
		if c := metrics.Global(); c != nil {
			c.CloseEventAndAdd(evt)
		}
	}()

	ctx := rootCtx

	ds, err := getFederatedStore()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Run the federation command through the normal `bd` CLI so root initialization opens the store first
  2. Fix the earlier store-initialization failure (check for prior connection errors — often the DB path or Dolt server config is wrong)
  3. Verify the working directory contains an initialized beads database (`.beads/`) before running federation commands
  4. If invoking programmatically, ensure the same PersistentPreRun/initialization path that sets the global `store` executes first

Example fix

// before: federation command assumes store exists
store, err := getFederatedStore() // errors: no store available
// after: ensure initialization happened before using the store
if err := rootCmd.PersistentPreRunE(federationCmd, args); err != nil { return err }
store, err := getFederatedStore()
Defensive patterns

Strategy: type-guard

Validate before calling

// before invoking federation subcommands programmatically, confirm the store is open
if store == nil {
    return fmt.Errorf("run via the bd CLI (or initialize the store) before federation commands")
}

Type guard

func hasFederatedStore() bool { return store != nil }

Try / catch

st, err := getFederatedStore()
if err != nil {
    return fmt.Errorf("federation requires an open database; run `bd` from a repo with .beads/: %w", err)
}

Prevention

When it happens

Trigger: Running `bd federation sync` or `bd federation status` in a context where the root command's persistent store initialization did not run (e.g. store left nil due to an earlier silent init failure, or the command being invoked through a path that bypasses PersistentPreRun).

Common situations: Invoking federation commands programmatically without going through root command execution; an earlier database-open failure that left `store` nil without aborting the command; unusual environments (embedded/proxied server mode) where store creation is skipped.

Related errors


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