Skip to content

Commit

Permalink
chore: don't error when calling #sendHaves without a peer (#691)
Browse files Browse the repository at this point in the history
We were effectively doing something like this:

```javascript
if (!object) {
  console.warn('no object', object.propertyAccessThatWillFail)
}
```

This could throw an error because we can't access properties on `null`
or `undefined`.[^0]

This updates the log message to avoid this error.

[^0]: It's possible that the value was another falsy value, such as
`false`, where you can technically access properties. I still think this
change is an improvement in that situation, because
`false.remotePublicKey` is `undefined`, which isn't very useful.
  • Loading branch information
EvanHahn authored May 29, 2024
1 parent 9f8e96e commit 002b981
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class CoreManager extends TypedEmitter {
*/
async #sendHaves(peer, cores) {
if (!peer) {
console.warn('sendHaves no peer', peer.remotePublicKey)
console.error('Called #sendHaves with no peer')
// TODO: How to handle this and when does it happen?
return
}
Expand Down

0 comments on commit 002b981

Please sign in to comment.