Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: better error handling 馃憤 #434

Merged

Conversation

habibalkhabbaz
Copy link
Contributor

@habibalkhabbaz habibalkhabbaz commented Jul 23, 2022

Description

After reading the bot logs using docker logs binance-bot -f --tail 100, I see that the bot still has unhandled promise rejection warnings from redlock which may cause the bot to crash or restart the WebSocket.

Screenshot_2

These warnings lead me to do some research, and I found that if any error is thrown inside callback function, setInterval or setTimeout will be ignored by the parent try/catch. One solution is to use try/catch inside each block which is hard to do this everywhere. So that's what this pull request is going to solve.

I managed to solve this by implementing a global error handler using process to handle errors that are not caught by the bot.
I know that may catch any unexpected error but this will give us the benefit of handling and debugging any error easily.

Also, this may help us to report any error to any service such as "Sentry" in the future if planned.

Finally,
I don't mind if you do any changes to this pull request.
Any change will be welcomed. Or even if you have a better idea.

How Has This Been Tested?

It was tested locally and test files were also provided

@chrisleekr
Copy link
Owner

@habibalkhabbaz

This is looking really good. 馃憤
The code looks good. Let me test and merge later.

@chrisleekr chrisleekr merged commit e5e2650 into chrisleekr:master Jul 23, 2022
@chrisleekr
Copy link
Owner

@habibalkhabbaz
Released!

Thanks for the really good code!

@habibalkhabbaz
Copy link
Contributor Author

Ohh, that was fast. Thank you for merging @chrisleekr
In fact, it was your idea and I just tried to refactor it.
Thanks again and happy trading!

SardorAbdullaev added a commit to SardorAbdullaev/binance-trading-bot that referenced this pull request Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants