nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

nw-0.13-beta3 Windows: "Invisible" Uncaught Exception

Open brandonkirsch opened this issue 10 years ago • 5 comments

I have an issue with uncaught exceptions in nwjs 0.13-beta3 for Windows. This problem DOES NOT occur in nwjs 0.12.3.

In certain circumstances, uncaught Node.js exceptions are occurring silently and do not appear in the DevTools Console.

In my case, I am using Node dgram.Socket "message" event handler. If I trigger an exception on a Node object (examples include: nw.require('doesNotExist') & Buffer.read(outOfBounds)) then the event stops processing and the exception goes unreported on the DevTools console.

I would expect to see the uncaught error appear in DevTools Console (as it does in v12).

Pastebin example: http://pastebin.com/maWsA4Ms

brandonkirsch avatar Jan 14 '16 16:01 brandonkirsch

You should check not only your window devconsole, but also a background page's one, or maybe others (depending on your setup). I'm uncertain about how exactly an exception routed in nwjs in various context combinations, but I suppose the console where it appears depends on context that raized an exception; it may not be a context of window which devconsole you are inspecting. You can check that by adding window handler for error events, if it hits, you can expect your exception in devconsole of that window. And finally, have a look at 0.12 to 0.13 migration notes' architecture changes:

The Node.js context is put in the DOM context of the background page, which is shared between opening windows as in 0.12 and before.

Therefore if our node.js part of chimera raize an exception, it's stack trace ends up in background page, not your window.

offshore avatar Jan 14 '16 17:01 offshore

Hi offshore. I am using a simple one-page "index.html" as the main module.

From what I understand, the "background page" context should be shared with my main module's window so I believe I should be seeing those anyways.

In any case, I have tried attaching 'uncaughtException' handlers everywhere I can find, including nw.global.process and window.opener.process and it just doesn't seem to be happening.

I have a feeling that the exception is being caught somewhere, preventing it from becoming "unhandled" which keeps it from showing up in the console.

brandonkirsch avatar Jan 14 '16 18:01 brandonkirsch

Try following: insert alert('blah'); somewhere in the beginning, then launch your app with remote debugging: nw --remote-debugging-port=9222 path/to/app, open http://localhost:9222 in any browser and then click "OK" in that alert modal. Then check all of your devconsoles.

offshore avatar Jan 14 '16 18:01 offshore

And there you have it: my uncaught exceptions are going to the "background" window.

How I am supposed to be able to catch that from my primary application window is still fuzzy, but I will keep trying to learn.

brandonkirsch avatar Jan 14 '16 18:01 brandonkirsch

Well, you can try window.console.*(...) instead of console.*(...) or something. Just reference the window properly. Finaly, and this is most reliable way, you can wrap your code in try/catch and propagate your exceptions via callback's first argument, just like Node.js does in it's async API.

offshore avatar Jan 14 '16 19:01 offshore