nsk
nsk

Reputation: 255

Cloud function deployment failure

I am trying to deploy my Cloud Function using Cloud Firestore as Trigger. The Cloud function simply listens to any new document creation on my firestore path and logs the new data to the console. However, the function deployment is failing and there is no clear error message. Could you please help me identify what could be the issue?

Cloud Function Code:

const functions = require('firebase-functions');

exports.createUser = functions.firestore
    .document('test_restaurant/{id}/reviews/{id}')
    .onCreate((snap, context) => {
    
        console.log(snap.data());
      
    });

Error Log:

2020-06-28 18:51:03.110 IST
Cloud Functions
UpdateFunction
asia-east2:function-test-2
[email protected]
Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs
Expand all | Collapse all
{
 insertId: "5u231ccch0"  
 logName: "projects/fs-22/logs/cloudaudit.googleapis.com%2Factivity"  
 
operation: {
  id: "operations/ZmlyZXN0b3JlLTI0OTcwNS9hc2lhLWVhc3QyL2Z1bmN0aW9uLXRlc3QtMi9xOVJCbHpESzdjSQ"   
  last: true   
  producer: "cloudfunctions.googleapis.com"   
 }
 
protoPayload: {
  @type: "type.googleapis.com/google.cloud.audit.AuditLog"   
  
authenticationInfo: {
   principalEmail: "[email protected]"    
  }
  methodName: "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction"   
  resourceName: "projects/fs-22/locations/asia-east2/functions/function-test-2"   
  serviceName: "cloudfunctions.googleapis.com"   
  
status: {
   code: 3    
   message: "Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs"    
  }
 }
 receiveTimestamp: "2020-06-28T13:21:03.364975479Z"  
 
resource: {
  
labels: {
   function_name: "function-test-2"    
   project_id: "fs-22"    
   region: "asia-east2"    
  }
  type: "cloud_function"   
 }
 severity: "ERROR"  
 timestamp: "2020-06-28T13:21:03.110Z"  
}

Upvotes: 2

Views: 3030

Answers (3)

andress hoyo
andress hoyo

Reputation: 171

If you are using lint, you need to make sure your code is passing eslint . command, other wise youl'll get that error deploying to firebase

{
  "@type":"type.googleapis.com/google.cloud.audit.AuditLog",
  "status":{
    "code":3,
    "message":"Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging"
  },
  "authenticationInfo":{
    "principalEmail":"your_email"
  },
  "serviceName":"cloudfunctions.googleapis.com",
  "methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
  "resourceName":"projects/your_project/locations/us-central1/functions/your_func"
}

For my case I fix it by dissabling prettier on index, also, if you have more files you have to disable it for each one.

/* eslint-disable prettier/prettier */

Upvotes: 0

Enzo Barrera
Enzo Barrera

Reputation: 465

Check if you have some dependencies installed on your root folder. You should have all your modules installed inside the functions folder. Only firebase dependencies should be in your root folder. Try to do npm uninstall yourDependencie inside your root folder and then npm i yourDependencie inside root/functions folder.

Upvotes: 0

nsk
nsk

Reputation: 255

The issue resolved. Basically the error was using the same wildcard twice in the document path. The reference causing the problem was {id}, I just changed one of those references. The new path is: .document('test_restaurant/{id}/reviews/{reviewsId}') and the deployment succeeded.

Upvotes: 1

Related Questions