简体   繁体   中英

Error INTERNAL from Firebase Cloud Function

There is myFunction in Firebase Cloud Functions:

const myFunctionHandler = (params, context) => {
  return new Promise((resolve, reject) => {
    return admin
      .database()
      .ref("checks")
      .push(params)
      .then((r) => resolve(r))
      .catch((e) => reject(e));
};
exports.myFunction = functions.https.onCall(myFunctionHandler);

this is how I call it from the client:

  functions()
    .httpsCallable('myFunction')({
      myParam: true,
    })
    .then(resp => console.log(resp))
    .catch(e => console.log(e));

In the Firebase Cloud Functions these are the logs:

Function execution started
Unhandled error RangeError: Maximum call stack size exceeded
at Function.mapValues (/workspace/node_modules/lodash/lodash.js:13426:7)
at encode (/workspace/node_modules/firebase-functions/lib/providers/https.js:183:18)
at encode (/workspace/node_modules/firebase-functions/lib/providers/https.js:157:16)
at /workspace/node_modules/lodash/lodash.js:13427:38
at /workspace/node_modules/lodash/lodash.js:4925:15
at baseForOwn (/workspace/node_modules/lodash/lodash.js:2990:24)
at baseForOwn (/workspace/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/workspace/node_modules/lodash/lodash.js:13426:7)
Function execution took 2438 ms, finished with status code: 500

After 2438ms the data is entered correctly in Firebase Realtime Database but the response gives [Error: INTERNAL] . Why?

[EDIT]

I've tried to copy the same database push function in the client like this:

database()
      .ref()
      .child(`checks`)
      .push(params)
      .then(r => resolve(r))
      .catch(e => reject(e));

and the response I have is: https://myApp.firebaseio.com/checks/-MHABiZl5lsDBLSP22-3 that is a positive feedback that tells me the info are stored correctly.

I aspect the same positive response from the Cloud Functions BUT what I have is the [Error: INTERNAL] .

Receiving (from the function in the Firebase Cloud Functions) an Error as response the idea I have is that the info are not stored correctly.

Callable functions send a JSON payload to the client. That's all they can send. When you return a promise from a callable function, it will attempt to serialize the object resolved from the promise. The object you're trying to send (the result of a push() is a ThennableReference ) is too complex for serialization, so it fails. It contains self-referential links, which causes the error you see.

Your question still doesn't indicate exactly what the JSON payload is supposed to be. You're going to have to figure out what that is, and send only that object to the client. It obviously can't be a ThennableReference. If you need to convert that to something, figure out how to convert it, and send that object instead.

The same function gives different response from ether client or server. In the FCF I just avoid it to parse the response of the push. In the client it returns the https link as described in the google documentation.

Be sure also the localhost:5001 Node server is not running. In my case interfered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM