ipfs/kubo · critical
no peer ID in config! (was 'ipfs init' run?)
Error message
no peer ID in config! (was 'ipfs init' run?)
What it means
Defensive duplicate check for the same Identity section: after the empty-string check, a non-empty-but-zero-length PeerID (impossible in practice via the same field, but guarded for safety) also fails node construction. Same root cause and remedy as the "identity was not set" error: the repo has no usable peer identity.
Source
Thrown at core/node/groups.go:276
cacheOpts,
cfg.Datastore.HashOnRead,
cfg.Datastore.WriteThrough.WithDefault(config.DefaultWriteThrough),
cfg.Provide.Strategy.WithDefault(config.DefaultProvideStrategy),
)),
finalBstore,
)
}
// Identity groups units providing cryptographic identity
func Identity(cfg *config.Config) fx.Option {
// PeerID
cid := cfg.Identity.PeerID
if cid == "" {
return fx.Error(errors.New("identity was not set in config (was 'ipfs init' run?)"))
}
if len(cid) == 0 {
return fx.Error(errors.New("no peer ID in config! (was 'ipfs init' run?)"))
}
id, err := peer.Decode(cid)
if err != nil {
return fx.Error(fmt.Errorf("peer ID invalid: %s", err))
}
// Private Key
if cfg.Identity.PrivKey == "" {
return fx.Options( // No PK (usually in tests)
fx.Provide(PeerID(id)),
fx.Provide(libp2p.Peerstore),
)
}
sk, err := cfg.Identity.DecodePrivateKey("passphrase todo!")
if err != nil {View on GitHub (pinned to 329838acdf)
Solutions
- Initialize Identity.PeerID to a valid peer ID before building the node (library use)
- Run `ipfs init` for CLI/daemon use
- Review code that builds config.Config programmatically — this guard suggests a struct built with an empty Identity
Example fix
// before (library code)
cfg := &config.Config{} // Identity unset
// after
cfg := &config.Config{ Identity: config.Identity{ PeerID: peerIDStr, PrivKey: keyStr } } Defensive patterns
Strategy: validation
Validate before calling
if cfg.Identity == nil || len(cfg.Identity.PeerID) == 0 {
return errors.New("config.Identity.PeerID must be a non-empty peer ID")
} Prevention
- When building config.Config in library code, always populate Identity explicitly
- Validate configs with peer.Decode before use
- Never serialize/deserialize config structs into a lossy format
When it happens
Trigger: `len(cid) == 0` after `cid != ""` passed — effectively a parallel guard in Identity(cfg); reachable only through unusual config states or programmatic config construction with a nil/empty PeerID variant.
Common situations: Programmatically constructed config.Config structs (e.g. kubo-as-a-library users) leaving Identity.PeerID as its zero value; partially deserialized configs.
Related errors
- identity was not set in config (was 'ipfs init' run?)
- unrecognized key type: %s
- ipfs not initialized, please run 'ipfs init'
- cannot set Identity.PeerID to a value that does not match th
- failed to get PrivKey
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/df9d14d92df5c6af.
Report an issue: GitHub.