{"record":{"id":"4574f56dfb590077","repo":"ipfs/kubo","slug":"getclosestpeers-key-is-undefined","errorCode":null,"errorMessage":"GetClosestPeers key is undefined","messagePattern":"GetClosestPeers key is undefined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/corehttp/routing.go","lineNumber":107,"sourceCode":"\nfunc (r *contentRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error {\n\tctx, cancel := context.WithCancel(ctx)\n\tdefer cancel()\n\n\traw, err := ipns.MarshalRecord(record)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// The caller guarantees that name matches the record. This is double checked\n\t// by the internals of PutValue.\n\treturn r.n.Routing.PutValue(ctx, string(name.RoutingKey()), raw)\n}\n\nfunc (r *contentRouter) GetClosestPeers(ctx context.Context, key cid.Cid) (iter.ResultIter[*types.PeerRecord], error) {\n\t// Per the spec, if the peer ID is empty, we should use self.\n\tif key == cid.Undef {\n\t\treturn nil, errors.New(\"GetClosestPeers key is undefined\")\n\t}\n\n\tkeyStr := string(key.Hash())\n\tvar peers []peer.ID\n\tvar err error\n\n\tif r.n.DHTClient == nil {\n\t\treturn nil, fmt.Errorf(\"GetClosestPeers not supported: DHT is not available\")\n\t}\n\n\tswitch dhtClient := r.n.DHTClient.(type) {\n\tcase *dual.DHT:\n\t\t// Only use WAN DHT for public HTTP Routing API.\n\t\t// LAN DHT contains private network peers that should not be exposed publicly.\n\t\tif dhtClient.WAN == nil {\n\t\t\treturn nil, fmt.Errorf(\"GetClosestPeers not supported: WAN DHT is not available\")\n\t\t}\n\t\tpeers, err = dhtClient.WAN.GetClosestPeers(ctx, keyStr)","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/routing.go#L89-L125","documentation":"The Routing RPC endpoint was called to find closest peers with cid.Undef as the key. Although the spec says an empty peer ID should default to self, this guard rejects an undefined CID key rather than guessing an intent for it.","triggerScenarios":"Thrown at core/corehttp/routing.go:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an actual CID to route the query to (e.g. from 'ipfs routing findprovs')","If you wanted this node's closest peers, pass the node's own CID-derived key explicitly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}