fix: return empty array when no multiaddrs are known

Returning `undefined` makes the address length check in [dialler/index.js](https://github.com/libp2p/js-libp2p/blob/master/src/dialer/index.js#L73-L75)
fail with `cannot read property length of undefined` so the change
here is to always return an array, but it might be empty if we don't
know any multiaddrs for the given peer.
This commit is contained in:
achingbrain 2020-07-20 10:51:29 +01:00
parent 856b38de67
commit ed2dbd9bea
2 changed files with 3 additions and 3 deletions

View File

@ -179,7 +179,7 @@ class AddressBook extends Book {
const record = this.data.get(peerId.toB58String())
if (!record) {
return undefined
return []
}
return record.map((address) => {

View File

@ -323,10 +323,10 @@ describe('addressBook', () => {
throw new Error('invalid peerId should throw error')
})
it('returns undefined if no multiaddrs are known for the provided peer', () => {
it('returns empty array if no multiaddrs are known for the provided peer', () => {
const addresses = ab.getMultiaddrsForPeer(peerId)
expect(addresses).to.not.exist()
expect(addresses).to.be.empty()
})
it('returns the multiaddrs stored', () => {