GoogleCloudPlatform / functions-framework

The Contract for Building New Function Frameworks
Apache License 2.0
123 stars 11 forks source link

TypeError: callback is not a function #44

Closed scarolan closed 3 years ago

scarolan commented 3 years ago

I'm running a function locally using --signature-type=cloudevent and I attempted to send sample PubSub data into it per the docs:

https://cloud.google.com/functions/docs/running/calling#background_functions

The error I get is below. The code works fine (including the callback) if I deploy it to Google Cloud Functions.

Unhandled rejection
TypeError: callback is not a function
    at pollenCount (C:\Users\sean\git_repos\pollencount\index.js:115:5)
Error: Process exited with code 16
    at process.<anonymous> (C:\Users\sean\git_repos\pollencount\node_modules\@google-cloud\functions-framework\build\src\invoker.js:275:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:467:12)
    at process.exit (internal/process/per_thread.js:169:15)
    at Object.sendCrashResponse (C:\Users\sean\git_repos\pollencount\node_modules\@google-cloud\functions-framework\build\src\logger.js:37:9)
    at process.<anonymous> (C:\Users\sean\git_repos\pollencount\node_modules\@google-cloud\functions-framework\build\src\invoker.js:271:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:467:12)
    at processPromiseRejections (internal/process/promises.js:245:33)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Here is how my callback looks inside the function:

 async function pollenCount(data, context, callback) {
 ...
    // Finally send the JSON data to the browser or requestor
    //res.status(200).send(output);
    callback(null, output);
  } catch (err) {
    //res.status(500).send(err.message);
    callback(new Error('Failed'));
  } finally {
    await closeConnection(page, browser);
  }
grant commented 3 years ago

Cloudevent functions are only used for .NET and ruby. It looks like you are using node.

Try event instead of cloudevent.

scarolan commented 3 years ago

Thanks Grant. I was confused by the note on this page:

https://github.com/GoogleCloudPlatform/functions-framework#specification-summary

Note: SIGNATURE_TYPE: event supports legacy, non-CloudEvent events. Support for these event formats are not required for Function Frameworks.

Anyway I'm glad to hear you are moving toward support for the industry standard cloudevent format. We can close this issue.