question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better error handling

See original GitHub issue

I’ve had CCXWS running on multiple exchanges and assets for a while now, and recently noticed that some exchanges (Binance in this case) will throw an error and cause my script to crash, even with a try catch around it. Below is the snippet I receive. I am trying to add logic to my code so I can catch this error and handle it myself and believe this is a bug. If it isn’t, please let me know how to handle it as there doesn’t appear to be any documentation and what I’ve tried so far hasn’t worked (try catch and websocket.on(‘error’)).

`info: watcher initiating reconnection info: reconnecting info: closing connection to wss://stream.binance.com:9443/stream?streams=bnbusdt@aggTrade info: attempting connection info: connecting to wss://stream.binance.com:9443/stream?streams=bnbusdt@aggTrade events.js:183 throw er; // Unhandled ‘error’ event ^

RangeError: Invalid WebSocket frame: invalid status code 1005 at Receiver.controlMessage (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:441:18) at Receiver.getData (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:329:42) at Receiver.startLoop (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:133:22) at Receiver._write (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/receiver.js:69:10) at doWrite (_stream_writable.js:397:12) at writeOrBuffer (_stream_writable.js:383:5) at Receiver.Writable.write (_stream_writable.js:290:11) at TLSSocket.socketOnData (/var/www/html/discord-node/node_modules/ccxws/node_modules/ws/lib/websocket.js:795:35) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:250:11) at TLSSocket.Readable.push (_stream_readable.js:208:10) at TLSWrap.onread (net.js:607:20) error: Forever detected script exited with code: 1 error: Script restart attempt #179`

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
bmancini55commented, Apr 18, 2019

@kobermeit excellent!

We just pushed a new version of CCXWS that increased the watcher timeout for Binance and allows use of the reconnectTimeoutMs constructor argument if you need to customize it (which is a bit simpler than the workaround I previously posted). No need to update to the new version unless you want to, as the workaround will work just fine.

More info: https://github.com/altangent/ccxws/releases/tag/v0.23.0

0reactions
bmancini55commented, Aug 5, 2019

Apologies, the property was reconnectIntervalMs as defined here: https://github.com/altangent/ccxws/blob/master/src/exchanges/binance-client.js#L15

The underlying cause of the unhandled exceptions was also recently addressed in this commit: https://github.com/altangent/ccxws/commit/a5fd310d2e4d93df0f8aeb1d85b62f8ffb1ee2c7

It is available in v0.26.1+

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better error handling in JavaScript | by Iain Collins - Medium
Establishing good error handling conventions in a project can make it easier to improve the user experience of your software, squash mysterious 'unknown...
Read more >
Better error handling in Golang: Theory and practical tips
For more complex error handling, you can define custom error types by implementing the Error() method, which returns the error string.
Read more >
Clean Code and the Art of Exception Handling - Toptal
Exception Handling: It's a Good Thing · Always create your own ApplicationError hierarchy · Never rescue Exception · Never rescue more exceptions than...
Read more >
Better error handling in Golang: Theory and practical tips
Long-running applications should handle errors gracefully instead of panicking. Even in cases where recovery is not possible (e.g. validating ...
Read more >
Better Error Handling In NodeJS With Error Classes
Use error classes specifically set up for your application; · Implement abstract error handlers; · Always use async/await; · Make errors expressive ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found