rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar
https://docs.rollbar.com/docs/javascript
MIT License
566 stars 212 forks source link

NodeJS - silence exit when enabled is false and captureUncaught is true #1099

Open francois06 opened 1 year ago

francois06 commented 1 year ago

First of all, thank you for this amazing library!

I have found an issue with Node.JS when an error occurs in development mode & when rollbar is not enabled.

Use case :

server.js

const app = require('./app');
app.start(config.server.port);

app.js

//...
throw new Error('lorem');
// ...

server.js require app.js and then I run

node server.js

Error: lorem (with trace) :+1: ==> ok

Now I add rollbar with enabled: false server.js

const rollbar = new Rollbar({
    accessToken: 'xxx',
    captureUncaught: true,
    captureUnhandledRejections: true,
    enabled: false,
});
const app = require('./app');
app.start(config.server.port);

node server.js

no error, no trace, silent exit :-1:

Other tests :

if enabled is true with verbose: true => Error is shown with trace

if enabled is true with verbose: false => silent exit no trace

if enabled is false with verbose: true ==> Wrong error is shown :

Error: Rollbar is not enabled at Notifier.log at Rollbar._log

IMHO problems come from this test, rollbar should re-throw error when it s not enabled. Or maybe when enabled is false captureUncaught should be automatically false

if enabled is false with captureUncaught: false ==> ok

My current trick to make this work :

captureUncaught: (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging'),
enabled: (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging'),

I hope my explanations are clear.

Environment:

tested on Node.js 16.x && 18.x rollbar 2.26.1 (NPM module)