-
Notifications
You must be signed in to change notification settings - Fork 214
Description
Steps to reproduce
- Create a simple pool
- Add a non existent relay
- Connect
- Note the
nostr.esm.js:574 Uncaught (in promise) undefinederror
I think the problem is that there's no await here:
Lines 56 to 59 in f43d23d
| relays.forEach(async relay => { | |
| let r = await this.ensureRelay(relay) | |
| if (!r) return | |
| let s = r.sub(filters, modifiedOpts) |
Well, to be clearer, the async function that's invoked by the .forEach() is not awaited anywhere. It's just started. Maybe the solution would be to change .forEach() to a .map() and wrap the output in a Promise.all()? But, that would mean that failure to connect to any single relay would crash the whole pool. I guess that's probably not what we want.
I've always found it challenging to handle errors on one of the relays in a group. I suppose ideally the errors would be made available to the client of the API in some way. But the current API wouldn't support anything like that.
Another approach would be to check if all relays have failed, and if they have, then fail the whole process. Perhaps instead of a Promise.all() then a Promise.race() would work for that...