Closed nchitnis1 closed 1 year ago
@nchitnis1 Can you find the Cloud Functions logs and paste them here? You can find them by navigating to the Firebase console, click on Functions, and click on the logs view link that will navigate you to the Google Cloud Logs Explorer page.
There were 3 logs, I am pasting them below
Function execution started
{
"textPayload": "Function execution started",
"insertId": "yp1cb1ej1zxc",
"resource": {
"type": "cloud_function",
"labels": {
"project_id": "myprogram",
"region": "us-central1",
"function_name": "annotateImage"
}
},
"timestamp": "2023-02-10T17:18:14.855705886Z",
"severity": "DEBUG",
"labels": {
"execution_id": "8bltpxlffr3z"
},
"logName": "projects/myprogram/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"trace": "projects/myprogram/traces/ff32483817543f97dc647659d3ad34c6",
"receiveTimestamp": "2023-02-10T17:18:14.862253032Z"
}
Callable request verification passed
{
"insertId": "63e67c590009c2cf136fc1af",
"jsonPayload": {
"verifications": {
"app": "MISSING",
"auth": "VALID"
},
"message": "Callable request verification passed"
},
"resource": {
"type": "cloud_function",
"labels": {
"project_id": "myprogram",
"function_name": "annotateImage",
"region": "us-central1"
}
},
"timestamp": "2023-02-10T17:18:17.639695Z",
"severity": "DEBUG",
"labels": {
"instance_id": "00c61b117cd8d3ca00f7839765823080aa5c4309032f93e1d4c0b2c89497326e98612cd72f8d69a3b220e0ed06a6dec4afec45a9443a152596",
"execution_id": "8bltpxlffr3z",
"firebase-log-type": "callable-request-verification"
},
"logName": "projects/myprogram/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"trace": "projects/myprogram/traces/ff32483817543f97dc647659d3ad34c6",
"receiveTimestamp": "2023-02-10T17:18:17.871985066Z"
}
Function execution took 2792 ms, finished with status code: 500
{
"textPayload": "Function execution took 2792 ms, finished with status code: 500",
"insertId": "1do9liyefun05",
"resource": {
"type": "cloud_function",
"labels": {
"project_id": "myprogram",
"region": "us-central1",
"function_name": "annotateImage"
}
},
"timestamp": "2023-02-10T17:18:17.648691187Z",
"severity": "DEBUG",
"labels": {
"execution_id": "8bltpxlffr3z"
},
"logName": "projects/myprogram/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"trace": "projects/myprogram/traces/ff32483817543f97dc647659d3ad34c6",
"receiveTimestamp": "2023-02-10T17:18:17.871985066Z"
}
It looks like something is happening during the execution of the annotateImage
in the function - https://github.com/firebase/functions-samples/blob/539345b1d7b3af7a7fd4fadaa54255329bdff3e3/vision-annotate-images/functions/src/index.ts#L23
Could you log out the error that is occurring and re-deploy the function? You can just do something like this:
...
try {
return await client.annotateImage(JSON.parse(data));
} catch (e) {
// Add logging here
console.log(e);
throw new functions.https.HttpsError("internal", e.message, e.details);
}
....
I added the log statement, and did a deploy (see output below) but I did not see anything. As a test, I changed the HttpsError function parameters with the parameters "test" to see if it is actually calling this changed function. (See code below). I don't see the new "test" output, when I run my Swift app, I continue to see the old output ( INTERNAL error). So this function is not being called.
When "firebase deploy --only functions:annotateImage" is run the file functions/lib/index.js is being overwritten, with the file in the functions/src/index.ts. But after this, it is not clear what is happening.
try {
return await client.annotateImage(JSON.parse(data));
} catch (e: any) {
//Added logging
console.log(e);
throw new functions.https.HttpsError("internal", "test", "test");
//throw new functions.https.HttpsError("internal", e.message, e.details);
}
When I run "firebase deploy --only functions:annotateImage" it completes successfully, see the output below:
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged /Users/nitin/dev1/learn_mlkit/functions-samples/vision-annotate-images/functions (153.13 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 16 function annotateImage(us-central1)...
✔ functions[annotateImage(us-central1)] Successful update operation.
i functions: cleaning up build files...
✔ Deploy complete!
The error is in the cloud function, there is redundant JSON.parse() call (data is already an object). It should be:
return await client.annotateImage(data);
@jakubrak Oh nice catch, I'll update the sample code to yank that out. Thanks!
@nchitnis1 Removing that function call & redeploying should fix your Cloud Functions issue
...
try {
return await client.annotateImage(data);
} catch (e) {
throw new functions.https.HttpsError("internal", e.message, e.details);
}
....
[REQUIRED] Environment info
firebase-tools: 11.22.0
Platform: macOS
[REQUIRED] Test case
I am following the instructions at firebase.google.com/docs/ml/ios/recognize-text, to get recognized text back, but I am seeing the following errors:
[REQUIRED] Steps to reproduce
Followed these steps below, but I had to make the changes listed in https://github.com/firebase/firebase-tools/issues/5486 to get it to work.
The output looks good:
Here is my Swift code, most of which I copied from firebase.google.com/docs/ml/ios/recognize-text
[REQUIRED] Expected behavior
Should authenticate successfully, then should return the recognized text
[REQUIRED] Actual behavior
My authentication function authenticate() works, and it prints out the first line, but I am seeing the following errors printed from the function firebaseRecognize() shown above: