-
Notifications
You must be signed in to change notification settings - Fork 213
Description
[REQUIRED] Version info
node:
v18.20.8
firebase-functions:
4.3.1
firebase-tools:
13.35.1
firebase-admin:
11.8.0
[REQUIRED] Test case
To reproduce this issue, create a Firebase project and deploy the following Cloud Function:
index.js
"use strict";
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.onAppRemoveEvent = functions.analytics.event("app_remove")
.onLog(async (event) => {
try {
console.log(JSON.stringify(event));
const API_ENDPOINT = "https://example.com/api/dummy-endpoint";
const response = await fetch(API_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(event),
});
if (response.ok) {
const responseData = await response.json();
console.log(responseData);
} else {
const errorText = await response.text();
console.error(errorText);
}
} catch (error) {
console.error(error);
}
return null;
});
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1",
"request": "^2.88.2",
"requestretry": "^4.1.1",
"web-push": "^3.4.4"
},
"devDependencies": {
"eslint": "^8.15.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^3.1.0"
},
"private": true
}
[REQUIRED] Steps to reproduce
-
Deploy the provided Cloud Function to a Firebase project.
-
Generate app_remove events.
-
Monitor Cloud Function logs for TypeError before user code execution.
[REQUIRED] Expected behavior
The function should be triggered consistently.
[REQUIRED] Actual behavior
Intermittently, when an app_remove event triggers the function, the following TypeError is thrown by the firebase-functions library before the callback code begins execution. This issue occurs approximately 50% of the time, preventing the function from processing the event.
TypeError: Cannot read properties of undefined (reading 'toString')
at unwrapValueAsString (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:207:25)
at copyFieldTo (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:156:23)
at copyField (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:163:5)
at new UserPropertyValue (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:136:9)
at /workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:119:67
at Array.map (<anonymous>)
at /workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:119:47
at copyFieldTo (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:156:23)
at copyField (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:163:5)
at new UserDimensions (/workspace/node_modules/firebase-functions/lib/v1/providers/analytics.js:118:9)
Were you able to successfully deploy your functions?
Yes, the functions deploys successfully. The issue occurs during the invocation of the deployed function when an app_remove event is received.