discord-giveaways icon indicating copy to clipboard operation
discord-giveaways copied to clipboard

Catch out all Promises

Open Tomato6966 opened this issue 3 years ago • 8 comments

Just catch out all promises in the next version please!

channel.send().catch(() => {})

members.fetch().catch(() => {});

Etc.

Tomato6966 avatar Dec 06 '21 20:12 Tomato6966

isn't that bad

Dragonizedpizza avatar Dec 08 '21 05:12 Dragonizedpizza

U can add a debug option to allow users to enable or disable log information(s)

Tomato6966 avatar Dec 08 '21 08:12 Tomato6966

I suggest that instead of just

<Promise>.catch(()=>{})

There should be a logger function or some sort of error handling that would handle Promise rejections gracefully and log it out to the console, with options to enable verbose messages

Something like this perhaps (just example, to get an idea about what I'm suggesting)

function logger(err) {
  // Do something to make error pretty for console.log
  console.log(err)
}

// So when catching a Promise

<Promise>.catch(logger)

Compositr avatar Jan 03 '22 10:01 Compositr

I suggest catching all promises as u said and instead of using a logger. Just emit a error event in gwsManager with the error and the gw so there is no need to enable/disable debug option. U can just listen to that event if u want.

imranbarbhuiya avatar Jan 03 '22 13:01 imranbarbhuiya

I'd suggest doing either:

Manager.start(...).catch(() => {});

in your code, or add a debug option to the module like tomato said,

Manager.start({ ..., debug: false /* true by default */ });

which does catch the promises.

Dragonizedpizza avatar Jan 03 '22 16:01 Dragonizedpizza

I suggest catching all promises as u said and instead of using a logger. Just emit a error event in gwsManager with the error and the gw so there is no need to enable/disable debug option. U can just listen to that event if u want.

I would favor a event one too. I mean mongoose and I think other modules do it with a event too right?

Nico105 avatar Jan 03 '22 18:01 Nico105

I'd suggest doing either:

Manager.start(...).catch(() => {});

in your code, or add a debug option to the module like tomato said,

Manager.start({ ..., debug: false /* true by default */ });

which does catch the promises.

the first one would just catch the error of the start function no? Not the ones during runtime.

Nico105 avatar Jan 03 '22 18:01 Nico105

ah yeah

Dragonizedpizza avatar Jan 06 '22 10:01 Dragonizedpizza