js-libp2p icon indicating copy to clipboard operation
js-libp2p copied to clipboard

Undefined services causes exception

Open marcus-pousette opened this issue 2 years ago • 4 comments

  • Version: 0.45.0

Severity:

Low

Description:

Creating a libp2p instance with services that are undefined creates a null pointer exception even if it is allowed by the types

createLibp2p({
...,
    services: {
         abc: undefined
    }
})

To mitigate this I think there needs to be a null check before this https://github.com/libp2p/js-libp2p/blob/710da918a89b6f6ee5d03c0d14a311efd40a1b8f/src/libp2p.ts#L167 to check if createService is a function.

I ended up with this error because I am generating different configs based on conditions, and this leads me to assign "undefined" to services relay occasionally

marcus-pousette avatar May 15 '23 07:05 marcus-pousette

Related: https://github.com/libp2p/js-libp2p/issues/1573

achingbrain avatar May 16 '23 15:05 achingbrain

A runtime check seems reasonable but this really shouldn't be allowed by the types.

achingbrain avatar Oct 06 '23 12:10 achingbrain

Will be closed by #2133 when that lands.

dhuseby avatar Apr 30 '24 15:04 dhuseby