Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase cloud function exits with code 16 what is error code 16 and where can I find more info?

one of my cloud functions on firebase exits with code 16 as an error.

I tried to google and find out what that code is but no luck at all.

Error: Process exited with code 16     at process.on.code (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:393:29)     at process.emit (events.js:189:13)     at process.EventEmitter.emit (domain.js:441:20)     at process.exit (internal/process/per_thread.js:168:15)     at logAndSendError (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:184:9)     at process.on.err (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:390:13)     at process.emit (events.js:189:13)     at process.EventEmitter.emit (domain.js:441:20)     at emitPromiseRejectionWarnings (internal/process/promises.js:119:20)     at process._tickCallback (internal/process/next_tick.js:69:34)  

Where can I find those error codes reported so I can understand why my function exits?

like image 647
Jimmy Kane Avatar asked Jul 22 '19 15:07

Jimmy Kane


People also ask

Where is the code stored in firebase?

Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers. Already using Cloud Functions in Google Cloud? Learn more about how Firebase fits into the picture.

Why cloud function deployment failed?

Cloud Functions deployment can fail if the entry point to your code, that is, the exported function name, is not specified correctly. Your source code must contain an entry point function that has been correctly specified in your deployment, either via Cloud console or Cloud SDK.


2 Answers

Apparently and after investigation, the error means something like: Headers already sent.

I had somewhere in my code a response.send() with headers and then, later on, I was sending another response.

Would be great if the Firebase team could elaborate with these issues and provide some documentation instead of leaving us blindfolded (to my understanding)

like image 62
Jimmy Kane Avatar answered Sep 17 '22 14:09

Jimmy Kane


An improperly terminated cloud function is the likely cause.

Here's what the firebase docs say:

  • Resolve functions that perform asynchronous processing (also known as "background functions") by returning a JavaScript promise.

  • Terminate HTTP functions with res.redirect(), res.send(), or res.end().

  • Terminate a synchronous function with a return; statement.

In short, watch out for floating promises and/or multiple calls to res or response.

I've also seen the Process exited with code 16 occur in tandem with:

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.     at GoogleAuth.getApplicationDefaultAsync (/srv/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)     at process._tickCallback (internal/process/next_tick.js:68:7) 
like image 30
cDitch Avatar answered Sep 20 '22 14:09

cDitch