How can I make JavaScript exceptions more informative? - javascript

A very frustrating thing about JavaScript is that if it fails on an external module, it doesn't tell you the line of your code that initiated the path.
For example:
Unhandled rejection RequestError: Error: socket hang up
at new RequestError (/../node_modules/request-promise/lib/errors.js:11:15)
at Request.RP$callback [as _callback] (/../node_modules/request-promise/lib/rp.js:60:32)
at self.callback (/../node_modules/request/request.js:199:22)
at Request.emit (events.js:95:17)
at Request.onRequestError (/../node_modules/request/request.js:821:8)
at ClientRequest.emit (events.js:95:17)
at Socket.socketOnEnd (http.js:1569:9)
at Socket.g (events.js:180:16)
at Socket.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickDomainCallback (node.js:492:13)
In what reality is this stack trace useful? Is there any way to get it to print the last "non node_module" call that resulted in the exception?

There are several node modules providing an "async stacktrace". They seem to provide a similar functionality to the Async checkbox in the Chrome developer tools (under "Sources"). I have never actually worked with any of them, and I don't think they're necessarily meant for production systems, but they may well be useful for a development environment.
A quick google search shows you a number of possible modules (e.g. async-stacktrace).

Related

ECONNRESET Meteor

I am suddenly getting this error & there is no way I am able to trace the issue, my server keeps crashing again & again, and I haven’t done any changes in months for sure.
events.js:288
throw er; // Unhandled 'error' event
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'
}
Anyone facing this issue or have solution to the crash?
I tried to comment as much code as possible to avoid this issue but no luck.
Can anyone help me if this error was faced by anyone?
This problem could be due to your connection,
may be you lost your internet connection or from your server so check your server is that running properly or not

Deploying contracts with truffle error: Contracts.compile is not a function

I am running through smart contract creation and deployment from scratch to reaffirm knowledge in the fundamentals of contract creation.
After successfully creating local accounts via $truffle develop and jumping into the development console via truffle console --network development (development can be replaced by whichever network name you have defined in truffle.js), running deploy --compile-all --reset returns the following error;
TypeError: Contracts.compile is not a function
at Object.run (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:202236:15)
at Command.run (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160767:20)
at Console.interpret (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:202606:25)
at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:203345:18)
at bound (node:domain:421:15)
at REPLServer.runBound [as eval] (node:domain:432:12)
at REPLServer.onLine (node:repl:893:10)
at REPLServer.emit (node:events:526:28)
at REPLServer.emit (node:domain:475:12)
at REPLServer.Interface._onLine (node:readline:487:10)
Any help would be much appreciated.

Getting this socket error in discord.js and can't debug it [duplicate]

This error randomly appears When leaving my discord bot online for too long, around 3-4 hours but sometimes the error occurs sooner and sometimes later. It's really bothering me.
events.js:188
throw err;
^
Error: Unhandled "error" event. ([object Object])
at Client.emit (events.js:186:19)
at WebSocketConnection.onError (D:\BasementMonster\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:374:17)
at WebSocket.onError (D:\BasementMonster\node_modules\ws\lib\event-target.js:128:16)
at emitOne (events.js:116:13)
at WebSocket.emit (events.js:211:7)
at _receiver.cleanup (D:\BasementMonster\node_modules\ws\lib\websocket.js:211:14)
at Receiver.cleanup (D:\BasementMonster\node_modules\ws\lib\receiver.js:557:13)
at WebSocket.finalize (D:\BasementMonster\node_modules\ws\lib\websocket.js:206:20)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
I wrestled with this problem for a while in my own code. The main problem is that the trace is completely unhelpful, and that the error occurs so infrequently as to make "run it in the terminal and wait" a futile task. Eventually, I was able to figure out that the Discord.js client itself was throwing an error -- this wasn't mentioned in any of the documentation I read, so I had no handler for it -- and since this oopsie happens in the Discord.js package itself, there was no line in my code for it to point to in the trace.
What needs to exist in the code somewhere is something along the lines of
client.on('error', (err) => {
console.log(err.message)
});
This is adjusted, of course, for whatever your Client object is, and whatever you want the error handling to be.
This specific trace, as far as I can tell, comes from losing Internet connection, which is something I want to have a record of, so instead of console.log() I called my own custom function that writes the event out to a logfile with a timestamp.
Testing this by running an instance of the bot and killing my Internet connection revealed that not only did the logging function work, but that Discord.js automatically restored the bot's session after it came back. (Your mileage may vary.)
You need to add an error handling event, like this:client.on('error', console.error);

RethinkDB / horizon: After some usage getting 400 Bad Request Errors resulting in ReqlRuntimeError.ReqlError [as constructor] after restart

After using horizon dev server for some time I suddenly get a '400 Bad Request Error'. After restarting the server I get the following error in the terminal:
at ReqlRuntimeError.ReqlError [as constructor] (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\errors.js:23:13)
at new ReqlRuntimeError (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\errors.js:90:51)
at mkErr (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\util.js:177:10)
at Feed.IterableResult._addResponse (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\cursor.js:75:27)
at TcpConnection.<anonymous> (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\net.js:360:22)
at TcpConnection.cancel (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\util.js:26:16)
at TcpConnection.cancel (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\net.js:783:43)
at wrappedCb (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\net.js:270:17)
at tryCatcher (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\util.js:26:23)
at Promise.successAdapter (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\nodeify.js:23:30)
at Promise._settlePromiseAt (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\promise.js:579:21)
at Promise._settlePromises (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\promise.js:697:14)
at Async._drainQueue (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\async.js:123:16)
at Async._drainQueues (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (c:\Users\carl\AppData\Roaming\npm\node_modules\horizon\node_modules\rethinkdb\node_modules\bluebird\js\main\async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
The error gets logged two to three times in a row and then it states:
Horizon ready for connections �
But when reconnecting to the server via 'localhost:8181' it states '400 Bad Request Error' in the console again.
The Admin Interface is showing no issues.
This happens while playing around with the code from the Getting Started Guide on a Win10 64bit machine using Node.js v4.4.4 and horizon v1.0.1.
Since I updated to horizon v1.0.2 I haven't had the problem anymore. Neither the ReqlRuntimeError nor the 400 Bad Request Error.

Problematic socket.parser.resume() error in node.js

This bug has been crashing my node.js server for the past one week. On average it seems to occur every 12 hours. Normally when an error occurs in node.js, node.js will tell you the line number and your source file that lead to the error. However, this error is so weird that it does not let me know where the error originates from in my source codes. I can't even find _http_server.js within the entire project and node modules. As such, I have been unable to pinpoint and eliminate the bug.
Without the stack trace module 'longjohn', I would get the following error message:
socket.parser.resume()
cannot read property resume of null (_http_server.js:442)
......
After I installed 'longjohn', I obtained the following error message:
TypeError: Cannot read property 'resume' of null
at socketOnDrain (_http_server.js:442:20)
at ServerResponse.updateOutgoingData [as _onPendingData] (_http_server.js:270:14)
at ServerResponse.OutgoingMessage._send (_http_outgoing.js:128:14)
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:470:16)
at ReadStream.ondata (_stream_readable.js:525:20)
at emitOne (events.js:77:13)
at ReadStream.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at ReadStream.Readable.push (_stream_readable.js:110:10)
at onread (fs.js:1744:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:576:17)
---------------------------------------------
at ReadStream.Readable.on (_stream_readable.js:655:33)
at ReadStream.Readable.pipe (_stream_readable.js:522:7)
at SendStream.stream (C:\XXXX\node_modules\express\node_modules\send\lib\send.js:533:10)
at SendStream.send (C:\XXXX\node_modules\express\node_modules\send\lib\send.js:480:8)
at C:\XXXX\node_modules\express\node_modules\send\lib\send.js:392:10
at FSReqWrap.oncomplete (fs.js:82:15)
worker 1760 died
It is worthwhile mentioning that I am using socket.io. I am also using an external service called Global Counter that displays the number of online users. I am running setInterval() in one of the workers to remove expired records.
Could someone tell me the meaning of these error messages, how the error occurs, and how I should solve it?
according to https://github.com/nodejs/node/issues/3508, you may fix this problem after upgrading nodejs to v4.2.3+ or v5.1.1+

Categories

Resources