Skip to content

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

Open
@francois06

Description

@francois06

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) πŸ‘
==> 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 πŸ‘Ž

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions