ipfs/kubo · error

could not read config: %w

Error message

could not read config: %w

What it means

After constructing the node, serveTrustlessGatewayOverLibp2p reads the repo config via node.Repo.Config() to check Experimental.GatewayOverLibp2p. Failure reading the config aborts startup with "could not read config". Unlike the CLI-level GetConfig, this reads the config from the already-open repo.

Source

Thrown at cmd/ipfs/kubo/daemon.go:1190

	go func() {
		wg.Wait()
		close(errc)
	}()

	return errc, nil
}

const gatewayProtocolID protocol.ID = "/ipfs/gateway" // FIXME: specify https://github.com/ipfs/specs/issues/433

func serveTrustlessGatewayOverLibp2p(cctx *oldcmds.Context) (<-chan error, error) {
	node, err := cctx.ConstructNode()
	if err != nil {
		return nil, fmt.Errorf("serveHTTPGatewayOverLibp2p: ConstructNode() failed: %s", err)
	}
	cfg, err := node.Repo.Config()
	if err != nil {
		return nil, fmt.Errorf("could not read config: %w", err)
	}

	if !cfg.Experimental.GatewayOverLibp2p {
		errCh := make(chan error)
		close(errCh)
		return errCh, nil
	}

	opts := []corehttp.ServeOption{
		corehttp.MetricsCollectionOption("libp2p-gateway"),
		corehttp.Libp2pGatewayOption(),
		corehttp.VersionOption(),
	}

	handler, err := corehttp.MakeHandler(node, nil, opts...)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Restore $IPFS_PATH/config (from backup or re-create with `ipfs init` defaults, preserving Identity keys).
  2. Fix permissions so the daemon user can read the file.
  3. Do not delete or move the config while the daemon is starting; stop the daemon before editing.
  4. Check the wrapped inner error for the exact filesystem cause (ENOENT vs EACCES).

Example fix

// before
$ rm $IPFS_PATH/config  # daemon later fails
// after
$ ipfs shutdown  # edit only when stopped
$ ipfs config show > config.bak  # keep a backup
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(filepath.Join(ipfsPath, "config")); err != nil {
    return fmt.Errorf("config missing before daemon start: %w", err)
}

Try / catch

if err != nil && strings.Contains(err.Error(), "could not read config") {
    log.Fatalf("restore $IPFS_PATH/config (backup or ipfs init): %v", err)
}

Prevention

When it happens

Trigger: node.Repo.Config() errors: config file deleted/renamed after repo open, unreadable due to permissions, or a repo-level read error (datastore/config layer).

Common situations: Config file removed while the daemon is starting; another process rewrote/locked the file; permission change mid-run; a plugin or supervisor replacing $IPFS_PATH between init and read.

Related errors


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