Functions-samples: Can't delete or overwrite function that failed to deploy earlier

Created on 16 Apr 2017  Â·  13Comments  Â·  Source: firebase/functions-samples

I had an error in a function and when I tried to deploy it, it failed with an error message. I then fixed the error and tried to redeploy, but it would still show me the same error message. So I thought I could delete the function, but it still produces the same error. I even tried to re-deploy with an empty index.js file, to reset it, but it wouldn't work. The working functions get deleted successfully, but the function that had the error in it, won't go. I'll paste the command line output, that should make it clearer what the error is:

$ mv index.js index.bak
$ touch index.js
$ firebase deploy

=== Deploying to 'foo'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  starting release process (may take several minutes)...
i  functions: deleting function bar...
i  functions: deleting function foo...
i  functions: deleting function fooNew...
âš   functions[foo]: Deploy Error: Failed to configure trigger GCS Bucket: undefined
✔  functions[bar]: Successful delete operation.
✔  functions[fooNew]: Successful delete operation.
✔  functions: 2 function(s) deployed successfully.

Then if I leave index.js empty and re-run deploy, I get:

$ firebase deploy --only functions

=== Deploying to 'foo'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  starting release process (may take several minutes)...
i  functions: deleting function foo...
âš   functions[foo]: Deploy Error: Failed to configure trigger GCS Bucket: undefined

No matter how many times I re-run the command, it produces the same output. For some reason it won't delete the foo function.

Most helpful comment

I recently had an issue similar to this. I was trying to deploy functions, but the previous deployment was still in process (for like 15 minutes). I tried to delete the functions from the Google Cloud Functions console manually, and the delete process itself then took another 10 minutes. Eventually, they did delete and I was able to re-deploy. I think there was something funky going on, on Google's end.

After the delete completed successfully, I was able to deploy again without issue.

All 13 comments

can you include your package.json file contents? Also, have you checked your logs? Can we see those? make sure you run npm install before you try to deploy

Thanks for your reply. Here is the contents of package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "@google-cloud/storage": "^0.4.0",
    "child-process-promise": "^2.2.0",
    "ffmpeg-static": "^2.0.0",
    "firebase": "^3.7.8",
    "firebase-admin": "~4.1.2",
    "firebase-functions": "^0.5",
    "lodash": "^4.17.4",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^4.0.0"
  },
  "private": true
}

Here is a sample log entry for the failed execution:
8:24:34.924 pm warning userSubmttedVideoUploadLstener Failed to configure trigger GCS Bucket: undefined
I can't find more in the log about the userSubmttedVideoUploadLstener function.

I did run npm install before deploying.

Also, I tried to deleting the function using the Google Cloud web interface (https://console.cloud.google.com/functions/list?project=xxx). When I hit the delete function button, it shows a notification saying: Deleting function successfully started. But the function never seems to get deleted.

UPDATE:
In Google Cloud, the log entry is more verbose:

{
 protoPayload: {
  @type: "type.googleapis.com/google.cloud.audit.AuditLog"    
  status: {
   code: 13     
   message: "Failed to configure trigger GCS Bucket: undefined"     
  }
  serviceName: "cloudfunctions.googleapis.com"    
  methodName: "google.cloud.functions.v1beta2.CloudFunctionsService.DeleteFunction"    
  resourceName: "projects/xxx/locations/us-central1/functions/userSubmttedVideoUploadLstener"    
 }
 insertId: "54D876B9438E8.A034086.B80CDE1B"   
 resource: {
  type: "cloud_function"    
  labels: {
   project_id: "xxx"     
   region: "us-central1"     
   function_name: "userSubmttedVideoUploadLstener"     
  }
 }
 timestamp: "2017-04-19T16:21:44.352Z"   
 severity: "ERROR"   
 logName: "projects/xxx/logs/cloudaudit.googleapis.com%2Factivity"   
 operation: {
  id: "operations/bWVpbnRydW1wZi1mZDE0ZS91cy1jZW50cmFsMS91c2VyU3VibXR0ZWRWaWRlb1VwbG9hZExzdGVuZXIvT2hXWkZtMWRkWlU"    
  producer: "cloudfunctions.googleapis.com"    
  last: true    
 }
}

It looks like this is a permissions issue with your storage bucket. I would try deleting your functions file locally (save your code), and re-create a local repo. But first, try firebase logout followed by firebase login to reset your auth tokens and maybe this will re-write your permissions for GCB. Then firebase init functions and drag in your old code files. Run npm install and try to re-deploy.

Thanks, I tried your instructions, but I still get the error that the function won't delete. It is not a big problem though as everything else seems to work fine, besides the warning message.

I have another related question however. I have a function that gets triggered when a file gets uploaded to a storage bucket. Then in that function, I download the file, process it and upload it to the bucket under a different name (similar to the generate-thumbnail example in this repository). Then for the newly uploaded file I can generate a download URL using:

`https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/${'path/to/processed/video.mp4'.replace(/\//g,'%2F')}?alt=media`

This URL is pretty long, so I want to shorten it with Dynamic Links. To do this I make a POST request to the webapi, e.g:
https://foo.app.goo.gl/?link=https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/user-submitted-videos%2path%2Fto%2Fprocessed%2Fvideo.mp4?alt=media

The problem is that the short link redirects to the URL .../user-submitted-videos/path/to/processed/video.mp4?alt=media, i.e. the %2F are changed back to / again and the URL doesn't work.

How can I make a short link that preservers the %2F? Also, is it correct to use the web api for Dynamic Links or is there something in firebase-functions or firebase-admin I can use?

Random guess; have you tried replacing the %2F with %%2F? ​

Thanks for your suggestion @inlined, with two % signs, it doesn't replace %2F with /, but it leaves the extra % sign, so that doesn't work neither.

Try this:
https://foo.app.goo.gl/?link=https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/user-submitted-videos%252path%252Fto%252Fprocessed%252Fvideo.mp4?alt=media

Awesome! Using %252F instead of %2F works.

Cool - can we close this issue @redpandatronicsuk?

I still can't delete the function, but its not a big problem for me, so you can close the issue. Thanks for your help!

@redpandatronicsuk Did you figure out how to delete the function? I have a similar problem and found your issue via google.

If you did it would be great if you could write an answer to my question on StackOverflow!

The function got deleted somehow, but I can't remember having done anything. I think it was a bug on the Firebase side that got fixed. Try contacting support.

I recently had an issue similar to this. I was trying to deploy functions, but the previous deployment was still in process (for like 15 minutes). I tried to delete the functions from the Google Cloud Functions console manually, and the delete process itself then took another 10 minutes. Eventually, they did delete and I was able to re-deploy. I think there was something funky going on, on Google's end.

After the delete completed successfully, I was able to deploy again without issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phuduong060196 picture phuduong060196  Â·  4Comments

beratuslu picture beratuslu  Â·  4Comments

Midhilaj picture Midhilaj  Â·  5Comments

rodrigosol picture rodrigosol  Â·  3Comments

artcab picture artcab  Â·  4Comments