Handle errors when unpacking swarm.peers() response #885
Description
The addition of the quic protocol means there are now peers on the network with a multiaddr that cannot be unpacked by older verions of js-multiaddr, and it throws.
In the current implementation of ipfsApi.swarm.peers()
we don't handle any errors that could occur when trying to wrap the peer addr from the repsonse in a Multiaddr:
the simplest solution would be to re-throw the error with an informative error message, but that still leaves us with the siutation when newer peers get added to the network, they can break my user-experience, as I suddenly start seeing 0 peers; js-ipfs-api throws an error if 1 peer appears invalid like in ipfs/ipfs-webui#878
A more helpful solution might be to provide some way to signal to the caller that some peers have information that we can't validate, but still do a best effort to return information about the response.
If we go the best-effort route, we've got
-
easy
- remove peers from the list if we hit an error trying to validate their info, and write a debug log. This is simple, but leaves the peer list that you get from ipfs-api containing fewer items than the http repsonse did, which is undesireable. -
hard
- update the api response info to include peers that can't be validated. We could add a property to an idividual peer likeerror
with the validation error, and theraw
with the unvalidated response data. Or we could pull out unvalidtable peers into a sepearate list and return two arrays, could bepeers
(the valid ones) andrawPeers
(all peers)...