Skip to content

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

Closed

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:

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Sep 19, 2023
  2. Lms24 commented on Sep 19, 2023

    @Lms24
    Member

    Hi @dancallaghan thanks for reporting and thanks for already debugging the issue!
    I agree, we should apply the same fix as for the event function.

    Since you already found the responsible line, are you interested in submitting a PR? We'd make sure to mention you as a contributor in the next release. If not, no worries, we'll try to fix it ourselves eventually.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Sep 19, 2023
  4. moved this to Waiting for: Community in GitHub Issues with 👀on Sep 19, 2023
  5. getsantry commented on Oct 11, 2023

    @getsantry

    This issue has gone three weeks without activity. In another week, I will close it.

    But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


    "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

  6. moved this from Waiting for: Community to No status in GitHub Issues with 👀on Oct 11, 2023
  7. AbhiPrasad commented on Apr 23, 2024

    @AbhiPrasad
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions