{"record":{"id":"447a261375893d49","repo":"ipfs/kubo","slug":"failed-to-parse-peer-address-s-s","errorCode":null,"errorMessage":"failed to parse peer address '%s': %s","messagePattern":"failed to parse peer address '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/ping.go","lineNumber":63,"sourceCode":"\t\tcmds.StringArg(\"peer ID\", true, true, \"ID of peer to be pinged.\").EnableStdin(),\n\t},\n\tOptions: []cmds.Option{\n\t\tcmds.IntOption(pingCountOptionName, \"n\", \"Number of ping messages to send.\").WithDefault(10),\n\t},\n\tRun: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {\n\t\tn, err := cmdenv.GetNode(env)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Must be online!\n\t\tif !n.IsOnline {\n\t\t\treturn ErrNotOnline\n\t\t}\n\n\t\taddr, pid, err := ParsePeerParam(req.Arguments[0])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse peer address '%s': %s\", req.Arguments[0], err)\n\t\t}\n\n\t\tif pid == n.Identity {\n\t\t\treturn ErrPingSelf\n\t\t}\n\n\t\tif addr != nil {\n\t\t\tn.Peerstore.AddAddr(pid, addr, pstore.TempAddrTTL) // temporary\n\t\t}\n\n\t\tnumPings, _ := req.Options[pingCountOptionName].(int)\n\t\tif numPings <= 0 {\n\t\t\treturn fmt.Errorf(\"ping count must be greater than 0, was %d\", numPings)\n\t\t}\n\n\t\tif len(n.Peerstore.Addrs(pid)) == 0 {\n\t\t\t// Make sure we can find the node in question\n\t\t\tif err := res.Emit(&PingResult{","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/ping.go#L45-L81","documentation":"The `ipfs ping` command wraps its argument with this message when `ParsePeerParam` cannot interpret it as a valid peer address or peer ID. The command accepts either a bare peer ID (CIDv1 base32 or base58 multihash) or a multiaddr that includes the `/p2p/<peerID>` component; anything else is rejected before any network activity. The wrapped underlying error names the exact parse failure.","triggerScenarios":"Running `ipfs ping` with an argument that is not a valid multiaddr with a /p2p/ component and not a parseable peer ID: a CIDv0 peer ID in an unsupported encoding, a truncated ID, an IPFS path (/ipfs/...), a multiaddr missing the peer-ID component (e.g. `/ip4/1.2.3.4/tcp/4001` with no /p2p/ part), or a malformed CID.","commonSituations":"Pasting a full gateway URL or a CID instead of a peer ID; passing a multiaddr copied from `ipfs id` after stripping the `/p2p/Qm...` suffix; scripts using old `/ipfs/<id>` address syntax; shell quoting mangling the argument.","solutions":["Verify the argument is either a valid peer ID (e.g. from `ipfs id` or `ipfs swarm peers` output) or a full multiaddr ending in `/p2p/<peerID>`.","If passing a multiaddr, append the `/p2p/<peerID>` component; `ipfs ping /ip4/1.2.3.4/tcp/4001/p2p/Qm...` is valid, `/ip4/1.2.3.4/tcp/4001` alone is not.","Convert a CIDv0 peer ID if needed: peer IDs in base58btc (starting Qm or 12D3...) are accepted; check for stray whitespace or quoting with `echo -n \"$ARG\" | xxd`.","In code, validate with the same library before calling: `peer.Decode(id)` for bare IDs or `peer.AddrInfoFromString(s)` for multiaddrs."],"exampleFix":"// before\nipfs ping /ip4/147.75.83.83/tcp/4001\n// error: failed to parse peer address '/ip4/147.75.83.83/tcp/4001': ...\n\n// after\nipfs ping /ip4/147.75.83.83/tcp/4001/p2p/QmSoLP4uB...\n// or just the peer ID:\nipfs ping QmSoLP4uB...","handlingStrategy":"validation","validationCode":"import (\n\t\"github.com/ipfs/boxo/peer\"\n)\n\nfunc validPeerArg(s string) bool {\n\t_, _, err := peer.AddrInfoFromString(s)\n\treturn err == nil\n}\n\n// before calling: ipfs ping <arg>\nif !validPeerArg(arg) {\n\t// surface a clear message before invoking the CLI\n}","typeGuard":"func isPeerIDOrAddrInfo(s string) bool {\n\tif _, err := peer.Decode(s); err == nil {\n\t\treturn true // bare peer ID\n\t}\n\t_, err := peer.AddrInfoFromString(s)\n\treturn err == nil // multiaddr with /p2p/<id>\n}","tryCatchPattern":"pid, err := peer.Decode(arg)\nif err != nil {\n\tai, aerr := peer.AddrInfoFromString(arg)\n\tif aerr != nil {\n\t\treturn fmt.Errorf(\"not a peer ID or multiaddr-with-peerID: %q: %w\", arg, aerr)\n\t}\n\tpid = ai.ID\n}","preventionTips":["Always take peer IDs from authoritative sources: `ipfs id`, `ipfs swarm peers`, `ipfs diag net` output.","If using a multiaddr, keep the trailing `/p2p/<peerID>` component intact when copying.","Trim whitespace and verify shell quoting before passing the argument.","Prefer bare peer IDs (Qm... / 12D3...) for simplicity; use full multiaddrs only when pinning a transport address."],"tags":["cli","peer-id","multiaddr","parsing"],"backgroundTag":"invalid-peer-address","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"}