Search code examples
firebasefirebase-realtime-databasegoogle-cloud-functions

Delete a Firebase Cloud Function which failed with `Deploy Error: undefined`


How can I delete a Firebase Cloud Function which deployed with Deploy Error: undefined?


Steps to reproduce my problem:

1) Create a new Firebase project

2) $ firebase init and setup functions

3) Paste the following code into functions/index.js

"use strict";
const functions = require('firebase-functions');

function aFunction() {
    return 'reports/posts';
}

function getCorruptTrigger() {
    return '/reports/posts/' + aFunction +'/createdAt'
}

exports.thisFnWillFailToDeploy = functions
    .database
    .ref(getCorruptTrigger())
    .onWrite(event => {});

4) firebase deploy --only functions

5) The function will fail to deploy as expected.


What I tried to delete the Cloud Function:

  • Removing the function from the index.js and deploying does not delete the function, instead I get functions[thisFnWillFailToDeploy]: Deploy Error: undefined
  • Deleting the Cloud Function in the Google Cloud Console does not delete the function. (I get a toast saying that the function will be deleted, but this is not the case. In the logs there is an Error with "status":{"code":13})
  • Creating an empty cloud function with the name thisFnWillFailToDeploy also results in Deploy Error: undefined

Solution

  • That function in your project is in a bad state. Apparently, deploying a function with a malformed ref causes problems with that function that can't be reversed on your own. That function will failed to deploy from the outset (not even having a chance to delete it yet). After that, you can no longer update or delete the function. You'll have to contact support to recover the function, if that's what you need. You should still be able to update or delete other functions in that project.

    I'm guessing it's because you have a typo in your function call that generated the name of the ref. You're missing parens on the call to aFunction. I imagine you meant for it to look like this:

    function getCorruptTrigger() {
        return '/reports/posts/' + aFunction() +'/createdAt'
    }
    

    If you deploy that in a new project instead, it should work.