google / ground-platform

Ground hosted components: Web console, Cloud Functions, db config
http://groundplatform.org
Apache License 2.0
205 stars 88 forks source link

[Feature] Firebase Functions v2 - Profobuf compatibility #2086

Open rfontanarosa opened 3 days ago

rfontanarosa commented 3 days ago

Trying to implement a v2 firebase trigger function, it returns this error:

Error: Failed to decode protobuf and create a snapshot.
    at entryFromArgs (/workspace/node_modules/firebase-functions/lib/logger/index.js:133:19)
    at Object.error (/workspace/node_modules/firebase-functions/lib/logger/index.js:120:11)
    at createSnapshotFromProtobuf (/workspace/node_modules/firebase-functions/lib/common/providers/firestore.js:61:16)
    at createSnapshot (/workspace/node_modules/firebase-functions/lib/v2/providers/firestore.js:172:59)
    at makeFirestoreEvent (/workspace/node_modules/firebase-functions/lib/v2/providers/firestore.js:209:15)
    at func (/workspace/node_modules/firebase-functions/lib/v2/providers/firestore.js:300:32)
    at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:119:25
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

generated by this:

function createSnapshot(event) {
    var _a, _b, _c, _d;
    if (((_a = event.datacontenttype) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) || Buffer.isBuffer(event.data)) {
        return (0, firestore_1.createSnapshotFromProtobuf)(event.data, getPath(event), event.database);
    }
    else if ((_b = event.datacontenttype) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
        return (0, firestore_1.createSnapshotFromJson)(event.data, event.source, (_c = event.data.value) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.value) === null || _d === void 0 ? void 0 : _d.updateTime, event.database);
    }
    else {
        logger.error(`Cannot determine payload type, datacontenttype is ${event.datacontenttype}, failing out.`);
        throw Error("Error: Cannot parse event payload.");
    }
}

@gino-m fyi

gino-m commented 1 day ago

Does this provide any clues? https://stackoverflow.com/questions/78051822/cloudtasksclient-causing-error-when-instantiated-in-firebase-functions-ondocume