Please don't silently catch errors
See original GitHub issueThis module has a few try/catch
blocks that catch errors without logging them. This can make debugging really hard, especially when you’re not using the promise
module yourself (This is currently hitting us in the janitor project, which uses the email-login module, which itself uses the then/promise
. Many errors in Janitor or its modules are just caught by then/promise
, leaving us hanging without any useful error message).
The offending try/catch
blocks are here, here, and here.
When I hack this module to add console.error(ex)
to all these silent catches, I finally see errors like this one for example:
Error: Template error: macro "=" didn't work.
Parameters: title,in,nosuchparser
Literal: $_parsers $_parsedtext0 $_parsernames1 $_parserparams2 $_i3 $_scopestr machines projects version title user scripts $_scope $_write $_end
Message: Template error: parser nosuchparser is missing.
at evalmachine.<anonymous>:74:9
at ContextifyScript.Script.runInContext (vm.js:32:29)
at ContextifyScript.Script.runInNewContext (vm.js:38:15)
at runner (/home/ubuntu/workspace/node_modules/@jankeromnes/camp/node_modules/fleau/fleau.js:247:12)
at /home/ubuntu/workspace/node_modules/@jankeromnes/camp/lib/camp.js:88:16
at Array.map (native)
at ServerResponse.res.template (/home/ubuntu/workspace/node_modules/@jankeromnes/camp/lib/camp.js:84:37)
at Object.exports.landingPage (/home/ubuntu/workspace/lib/routes.js:105:12)
at app.route (/home/ubuntu/workspace/app.js:97:12)
at gotQueries (/home/ubuntu/workspace/node_modules/@jankeromnes/camp/lib/camp.js:887:7)
(Which has nothing to do with then/promise
, but is in fact a legitimate error in janitor
template files parsed by the fleau
module… which we never see logged on our end, unless we hack your promise/src/core.js
).
Here is an example stack trace of an error that is silently caught (but we still log the stack trace later because we have another way of noticing that something went wrong so we log a new Error()
which has this stack trace):
[2017-07-06T11:55:43.839Z] Error: Something went wrong
at login.confirmEmail (/home/janx/janitor/lib/sessions.js:100:16)
at /home/janx/janitor/node_modules/email-login/src/api.js:194:13
at /home/janx/janitor/node_modules/email-login/src/registry.js:67:18
at tryCallOne (/home/janx/janitor/node_modules/fsos/node_modules/promise/lib/core.js:37:12)
at /home/janx/janitor/node_modules/fsos/node_modules/promise/lib/core.js:103:15
at flush (/home/janx/janitor/node_modules/asap/raw.js:50:29)
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
The line node_modules/fsos/node_modules/promise/lib/core.js:37:12
is where our valid exception gets vacuumed and never logged (so we don’t know what the actual error is).
Could you please log all the exceptions caught here with a console.error(ex)
?
Or maybe the silent exceptions are a symptom that some janitor
direct dependencies like fleau
, email-login
or fsos
use then/promise
in a wrong way?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
That’s probably because these are not silently being swallowed by
promise
. Instead they are being handled by some other code. If you have something like:That is not treated as an unhandled rejection by Promise (or indeed by node.js’s native Promises). This is similar to how if you write
try {throw new Error('whatever'); } catch (ex) {}
no tools will show you that error by default.I tried adding
require('promise/lib/rejection-tracking').enable({ allRejections: true });
at the top of mytests.js
file, but it didn’t work:promise
: https://travis-ci.org/JanitorTechnology/janitor/builds/251991510#L736