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.

Please don't silently catch errors

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ForbesLindesaycommented, Jul 12, 2017

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:

Promise.reject(new Error('whatever')).catch(err => {
  // handle the err
});

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.

0reactions
jankeromnescommented, Jul 10, 2017

I tried adding require('promise/lib/rejection-tracking').enable({ allRejections: true }); at the top of my tests.js file, but it didn’t work:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do Java people frequently consume exceptions silently?
When the police gets to the body, they don't have a clue of what has just happened. ... Java forces you to handle...
Read more >
Should a program fail on errors or silently ignore them
As a general rule, don't catch any exception you can't do anything about, unless you just plan to log and rethrow it. And...
Read more >
How to handle errors with grace: failing silently is not an option
How to handle errors with grace: failing silently is not an option ... Don't interrupt your code flow for errors you can fix,...
Read more >
Error hiding - Wikipedia
In computer programming, error hiding (or error swallowing) is the practice of catching an error or exception, and then continuing without logging, ...
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
But there's a syntax construct try...catch that allows us to “catch” errors so the ... If we don't need error details, catch may...
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