Matt
Matt

Reputation: 1632

Firebase functions throws uncatchable error

I'm calling the following Firebase function:

exports.getUserRecord = functions.https.onCall(async (data, context) => {
    try {
        //This successfully logs an existing uid in firestore, it should be retrievable
        console.log(context.auth.uid)

        const doc = admin.firestore().collection('user').doc(context.auth.uid);
        const res = await doc.get() //Isolated it down to this line that is failing
        return res
    } catch (err) {
        console.log(err)
        throw new functions.https.HttpsError('unavailable', 'some error message');
    }
});

When calling this function I receive the following error on the client:

POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL

On the server logs I see this error:

Unhandled error function error(...args) {
    write(entryFromArgs('ERROR', args));
} 

I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?

EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.

I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue

Upvotes: 2

Views: 402

Answers (1)

Edward Romero
Edward Romero

Reputation: 3106

Walked through the firebase-functions code for onCall at v3.11.0 and I don't see any other issues that could relate to this in the code since the fix

https://github.com/firebase/firebase-functions/issues/757

After discussing with @Matt about node_module versions we found that the issue is related to node_modules not having updated to latest once the upgrade was initially done.

Notes for anyone running into this issue in the future

If updating to latest for this module make sure to do the following to cover all bases,

Look into node_modules/firebase-functions/package.json attribute version to make sure that the proper version is installed.

Also take a look at your root folder package.json and package-lock.json to makes sure the proper versions are the latest.

If anything is not at version v3.9.1 or higher, then do the following,

    rm -rf node_modules
    npm i firebase-functions@latest --save
    

After that, double check everything again to make sure all is good.

Upvotes: 2

Related Questions