Skip to content

UnhandledRejection getting caught as UncaughtException #6963

Closed as not planned
@Sammaye

Description

@Sammaye

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

7.34.0

Framework Version

4.17.1

Link to Sentry event

https://delenta.sentry.io/issues/3902577770/?project=6739047&query=is%3Aunresolved&referrer=issue-stream

SDK Setup

        global.process.on('uncaughtException', (error) => {
            console.log('in uncaught exception', error);
        });

        const sentryOptions = {
            environment: config.APP_ENV === 'DEV'
                ? 'development'
                : (
                    config.APP_ENV.includes('ALPHA')
                        ? 'alpha'
                        : (config.APP_ENV === 'BETA' ? 'beta' : 'production')
                ),
            dsn: config.LOGS_SENTRY_DSN,
            // Set tracesSampleRate to 1.0 to capture 100%
            // of transactions for performance monitoring.
            // We recommend adjusting this value in production
            tracesSampleRate: 0.25,
            integrations: integrations => {
                const newIntegrations = integrations.filter(integration =>
                    integration.name !== 'OnUncaughtException' &&
                    integration.name !== 'Http' &&
                    integration.name !== 'LocalVariables'
                );

                newIntegrations.push(
                    new Sentry.Integrations.OnUncaughtException({exitEvenIfOtherHandlersAreRegistered: false}),
                    new Sentry.Integrations.Http({tracing: true}),
                    new Sentry.Integrations.LocalVariables({
                        captureAllExceptions: true,
                    })
                );

                if (app) {
                    newIntegrations.push(
                        // enable Express.js middleware tracing
                        new Tracing.Integrations.Express({app}),
                    );
                }

                return newIntegrations;
            },
        };

        Sentry.init(sentryOptions);

Steps to Reproduce

Make a new express action like:

export async function a(req, res, next) {
    try {
        const [
            ab,
        ] = await Promise.all([
            b(),
        ]);

        return res.status(200).json({
              ab
        });
    }catch(error){
        console.log('caught error');
        next(error);
    }
}

async b() {
    throw new Error('omg');
    return this.countsdtdfdst({});
}

And then simply attach this action to any route, like /blah and go to this route in something like postman

Expected Result

It handles this via the express middleware correctly and assigns all express information.

Actual Result

It instead strips all that and throws it as a uncaught exception:

[ERROR] 11:04:08 Error: omg
in uncaught exception Error: omg
    at Function.b
caught error
GET /blah 503 437.030 ms - 87
(node:3408) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)

If I remove the new Sentry.Integrations.OnUncaughtException({exitEvenIfOtherHandlersAreRegistered: false}), line it works

Metadata

Metadata

Assignees

Labels

Package: nodeIssues related to the Sentry Node SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions