Skip to content

Synchronous Lambda callback causes undesirable second captureException call #2956

@leemhenson

Description

@leemhenson

See example event here: null.<anonymous>

Package + Version

  • @sentry/serverless

Version:

5.25.0

Description

If the callback-based lambda invocation is used, as opposed to the Promise-based style, then @sentry/serverless pushes the error correctly, but then also sends an empty exception. The reason is because this line:

captureExceptionAsync(args[0], context, options).finally(() => reject(callback(...args)));

calls captureExceptionAsync with the error correctly, but then also calls .finally(... reject(callback(...))

which rejects this awaited promise with undefined (the return value of calling callback):

? await new Promise((resolve, reject) => {

which causes execution to drop into the catch block below which then calls captureExceptionAsync again, but this time passing undefined as e:

await captureExceptionAsync(e, context, options);

Solution

I guess the catch block could no-op if e === undefined or you could change the callbackWrapper

// from:
captureExceptionAsync(args[0], context, options).finally(() => reject(callback(...args)));

// to:
callback(...args);
reject(args[0]);

as that would then push the error through the catch block instead of the result of callback, and would also honour the rethrow option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions