Skip to content

Commit

Permalink
feat: add explicit error for case peer id not included in multiaddr (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdostert authored and daviddias committed Feb 5, 2018
1 parent 248d86d commit bd8a35a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Node extends libp2p {

> Dials to another peer in the network.
- `peer`: can be an instance of [PeerInfo][], [PeerId][] or [multiaddr][]
- `peer`: can be an instance of [PeerInfo][], [PeerId][], [multiaddr][], or a multiaddr string
- `protocol`: String that defines the protocol (e.g '/ipfs/bitswap/1.1.0')
- `callback`: Function with signature `function (err, conn) {}` where `conn` is a [Connection](https://github.com/libp2p/interface-connection) object

Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ class Node extends EventEmitter {
if (typeof peer === 'string') {
peer = multiaddr(peer)
}

const peerIdB58Str = peer.getPeerId()
if (!peerIdB58Str) {
throw new Error(`peer multiaddr instance or string must include peerId`)
}

try {
p = this.peerBook.get(peerIdB58Str)
} catch (err) {
Expand Down

0 comments on commit bd8a35a

Please sign in to comment.