Skip to content

TypeError: callback is not a function thrown by Sentry.GCPFunction.wrapCloudEventFunction #9044

Closed
@dancallaghan

Description

@dancallaghan

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/serverless

SDK Version

7.69.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

Sentry.GCPFunction.init({
  dsn: env.sentry.dsn,
  release: env.sentry.release,
  environment: env.sentry.environment,
  integrations: [
    new Integrations.RewriteFrames({
      root: global.__rootdir__,
    }),
  ],
})

Steps to Reproduce

  1. Set up a GCP PubSub Cloud Event function with a handler function that does not have the optional callback argument.
export const rawHandler: CloudEventFunction<PubSubData> = async (
  event
) => {
  try {
    console.log(event.data)
  } catch (e) {
    console.log(e)
  }
}
  1. Wrap your handler function in sentry
export const handler = Sentry.GCPFunction.wrapCloudEventFunction(
  rawHandler
)
  1. Run your function

Expected Result

No error is thrown

Actual Result

A TypeError: callback is not a function error is thrown after the handler function has finished executing.

This is the offending line of code https://github.com/getsentry/sentry-javascript/blob/master/packages/serverless/src/gcpfunction/cloud_events.ts#L62. It invokes a callback without checking if it exists first.

It looks like this was done for regular events, but not for cloud events.

See the following:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: serverlessIssues related to the Sentry Serverless SDK

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions