ipfs/kubo · error

failed to open repo: %w

Error message

failed to open repo: %w

What it means

openDiagDatastore opens the node's fsrepo directly (read-only datastore inspection by `ipfs diag datastore` commands); if fsrepo.Open(cctx.ConfigRoot) fails, the error is wrapped as 'failed to open repo'. The diag command needs standalone repo access and cannot proceed.

Source

Thrown at core/commands/diag.go:138

	},
}

const diagDatastoreHexOptionName = "hex"

type diagDatastoreGetResult struct {
	Key     string `json:"key"`
	Value   []byte `json:"value"`
	HexDump string `json:"hex_dump,omitempty"`
}

// openDiagDatastore opens the repo datastore and conditionally mounts any
// provider keystore datastores that exist on disk. It returns the composite
// datastore and a cleanup function that must be called when done.
func openDiagDatastore(env cmds.Environment) (datastore.Datastore, func(), error) {
	cctx := env.(*oldcmds.Context)
	repo, err := fsrepo.Open(cctx.ConfigRoot)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to open repo: %w", err)
	}

	extraMounts, extraCloser, err := node.MountKeystoreDatastores(repo)
	if err != nil {
		repo.Close()
		return nil, nil, err
	}

	closer := func() {
		extraCloser()
		repo.Close()
	}

	if len(extraMounts) == 0 {
		return repo.Datastore(), closer, nil
	}

	mounts := []mount.Mount{{Prefix: datastore.NewKey("/"), Datastore: repo.Datastore()}}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Stop the running daemon before using `ipfs diag datastore` commands
  2. Confirm IPFS_PATH points at the correct, initialized repo
  3. Check repo lock files and version compatibility; run `ipfs repo fsck` if locks are stale

Example fix

// before
ipfs diag datastore get /some/key   # while daemon running -> failed to open repo
// after
ipfs shutdown
ipfs diag datastore get /some/key
Defensive patterns

Strategy: validation

Validate before calling

if daemonRunning() { stopDaemon() } // repo lock held otherwise
os.Stat(filepath.Join(ipfsPath, "datastore")) // ensure repo exists

Try / catch

ds, cleanup, err := openDiagDatastore(env)
if err != nil && strings.Contains(err.Error(), "failed to open repo") { checkLockAndPath(); return }

Prevention

When it happens

Trigger: Running `ipfs diag datastore get/put` while the repo cannot be opened: another daemon holds the repo lock, IPFS_PATH is wrong, or the repo is corrupted/mismatched version.

Common situations: Trying to inspect the datastore while the daemon is running (lock contention); wrong IPFS_PATH; repo initialized by a newer kubo version.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/45ba8bd59bb52642. Report an issue: GitHub.