node.jsfirebaseerror-handlinggoogle-cloud-functions

Throw error in Firebase cloud function, but exclude it from Cloud Console error reporting


I wonder if there is a way to report an error to client from a callable Firebase cloud function, which would not be included in error reporting in Google Cloud? I.e. "this is an error for the client, but it's actually a valid function result, requiring no intervention/investigation".

The justification is simple. Suppose I want to attribute a referral to a user. Naturally, there can only be one referrer. So, if a user was already referred previously, I do not want to attribute a new one.

runWith({ timeoutSeconds: 60, memory: "256MB" }).https.onCall(async (data, context) => {
    ...
    // code above checks if 'referrer' is already set
    if (alreadyHasReferrer) {
        throw new HttpsError("failed-precondition", "referrer already set to another user")
    }
    ...
}

These errors do get reported in Cloud Console. I wonder if there is a way to exclude these? Maybe there is another way to throw them?

I think that in this case returning an error to the client is correct, but it really bothers me that these errors, which require no further investigation, may clutter our Error Reporting dashboard in Cloud Console.


Solution

  • I don't think this is a matter of some simple configuration that prevents the error from being logged. The Firebase SDK that handles the implementation details of callables is likely doing this logging. If you must keep your function code the way it is, your only real option here is to change the way the firebase-functions SDK works so that it doesn't log the error.

    Or, you can file a feature request issue on that repo and ask for some configuration that makes specific thrown errors not log.

    If you must be able to change this behavior right now, then you might want to consider: