Hi,
I have a bug when using firebase-emulator, here are some logs and the error
{"severity":"INFO","message":"------ runCloudEvent: calling trigger with {\n specversion: '1.0',\n type: 'google.cloud.firestore.document.v1.created',\n source: '//firestore.googleapis.com/projects/projects/demo-gouach/databases/(default)',\n id: 'e0cfdd27-757a-4217-a68e-7eb7145c0c2a',\n subject: 'documents/battery-bms-types/1865_v3.1',\n time: '2025-02-21T13:48:14Z',\n datacontenttype: 'application/protobuf',\n dataschema: 'https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/cloud/firestore/v1/data.proto',\n location: 'us-central1',\n project: 'demo-gouach',\n database: '(default)',\n namespace: '(default)',\n document: 'battery-bms-types/1865_v3.1',\n data: <Buffer 0a 94 06 0a 4e 70 72 6f 6a 65 63 74 73 2f 64 65 6d 6f 2d 67 6f 75 61 63 68 2f 64 61 74 61 62 61 73 65 73 2f 28 64 65 66 61 75 6c 74 29 2f 64 6f 63 75 ... 743 more bytes>\n}"}
{"severity":"ERROR","message":"Error: Failed to decode protobuf and create a snapshot.\n at entryFromArgs (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/logger/index.js:133:19)\n at Object.error (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/logger/index.js:120:11)\n at createSnapshotFromProtobuf (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/common/providers/firestore.js:61:16)\n at createSnapshot (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:172:59)\n at makeFirestoreEvent (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:209:15)\n at func (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:300:32)\n at /Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:526:16\n at runFunction (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:15)\n at runCloudEvent (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:523:11)\n at processBackground (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:490:16)"}
⚠ functions: TypeError: Cannot read properties of undefined (reading 'cloud')
at Function.decode (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/protos/compiledFirestore.js:1529:130)
at createSnapshotFromProtobuf (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/common/providers/firestore.js:57:52)
at createSnapshot (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:172:59)
at makeFirestoreEvent (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:209:15)
at func (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-functions@6.3.2_firebase-admin@13.1.0_encoding@0.1.13_/node_modules/firebase-functions/lib/v2/providers/firestore.js:300:32)
at /Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:526:16
at runFunction (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:15)
at runCloudEvent (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:523:11)
at processBackground (/Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:490:16)
at /Users/primet/work/gouach/code/gouach-backend/node_modules/.pnpm/firebase-tools@13.31.1_encoding@0.1.13/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:692:27
⚠ Your function was killed because it raised an unhandled error.
I dumped the protobuf data.bin and downloaded the data.proto from the given URL, that I join on this error, here is what happens when I decode it "raw" and with the schema
cat data.bin|protoc --decode_raw
1 {
1: "projects/demo-gouach/databases/(default)/documents/battery-bms-types/1865_v3.1"
2 {
1: "description"
2 {
17: "The v3.1 BMS for 1865 cells"
}
}
2 {
1: "fields"
2 {
6 {
1 {
1: "version"
2 {
17: "v3.1"
}
}
1 {
1: "cell_format"
2 {
17: "1865"
}
}
1 {
1: "min_voltage"
2 {
2: 8
}
}
1 {
1: "wired_communication_protocol"
2 {
17: "CAN"
}
}
1 {
1: "screw_sensing"
2 {
1: 1
}
}
1 {
1: "predischarge_current_amps"
2 {
3: 0x3fe3333333333333
}
}
1 {
1: "mosfet_count"
2 {
2: 12
}
}
1 {
1: "can_ic_model"
2 {
17: "TCAN1051H_SOIC"
}
}
1 {
1: "mosfet_model"
2 {
17: "BSC040N08"
}
}
1 {
1: "esp32_silicon_version"
2 {
17: "v3"
}
}
1 {
1: "can_resistor_model"
2 {
17: "TLP170G"
}
}
1 {
1: "esp32_flash_size_mb"
2 {
2: 16
}
}
1 {
1: "power_supply_model"
2 {
17: "LM5010A"
}
}
1 {
1: "battery_ic_model"
2 {
17: "BQ76952"
}
}
1 {
1: "shunt_count"
2 {
2: 3
}
}
1 {
1: "shunt_individual_value_milli_ohms"
2 {
2: 2
}
}
1 {
1: "fuse_model"
2 {
17: "0684L9400-01"
}
}
}
}
}
2 {
1: "created_at"
2 {
3: 0x41d9ee20f3a96873
}
}
2 {
1: "created_by_id"
2 {
17: "iKAl8bUSDYoAHQAEvdyMScLRJWaT"
}
}
2 {
1: "created_by_email"
2 {
17: "batbot@gouach.com"
}
}
3 {
1: 1740145614
2: 653618000
}
4 {
1: 1740145614
2: 653618000
}
}
3: ""
and with the schema
git clone https://github.com/googleapis/googleapis.git
protoc --proto_path=. --proto_path=googleapis --decode=google.events.cloud.firestore.v1.DocumentEventData data.proto < data.bin
value {
name: "projects/demo-gouach/databases/(default)/documents/battery-bms-types/1865_v3.1"
fields {
key: "created_at"
value {
double_value: 1740145614.647
}
}
fields {
key: "created_by_email"
value {
string_value: "batbot@gouach.com"
}
}
fields {
key: "created_by_id"
value {
string_value: "iKAl8bUSDYoAHQAEvdyMScLRJWaT"
}
}
fields {
key: "description"
value {
string_value: "The v3.1 BMS for 1865 cells"
}
}
fields {
key: "fields"
value {
map_value {
fields {
key: "battery_ic_model"
value {
string_value: "BQ76952"
}
}
fields {
key: "can_ic_model"
value {
string_value: "TCAN1051H_SOIC"
}
}
fields {
key: "can_resistor_model"
value {
string_value: "TLP170G"
}
}
fields {
key: "cell_format"
value {
string_value: "1865"
}
}
fields {
key: "esp32_flash_size_mb"
value {
integer_value: 16
}
}
fields {
key: "esp32_silicon_version"
value {
string_value: "v3"
}
}
fields {
key: "fuse_model"
value {
string_value: "0684L9400-01"
}
}
fields {
key: "min_voltage"
value {
integer_value: 8
}
}
fields {
key: "mosfet_count"
value {
integer_value: 12
}
}
fields {
key: "mosfet_model"
value {
string_value: "BSC040N08"
}
}
fields {
key: "power_supply_model"
value {
string_value: "LM5010A"
}
}
fields {
key: "predischarge_current_amps"
value {
double_value: 0.6
}
}
fields {
key: "screw_sensing"
value {
boolean_value: true
}
}
fields {
key: "shunt_count"
value {
integer_value: 3
}
}
fields {
key: "shunt_individual_value_milli_ohms"
value {
integer_value: 2
}
}
fields {
key: "version"
value {
string_value: "v3.1"
}
}
fields {
key: "wired_communication_protocol"
value {
string_value: "CAN"
}
}
}
}
}
create_time {
seconds: 1740145614
nanos: 653618000
}
update_time {
seconds: 1740145614
nanos: 653618000
}
}
update_mask {
}
Archive.zip
So it seems I manage to parse the protobuf just fine, not sure why it doesn't work in the code (I have the latest firebase-tools, and all the latest versions of the firebase packages, the "fake test database" that does this bug is created from scratch using a script, so there's no stall data or whatever)
this is the code to generate the data
function createdByBot(data: any, created_at: number | undefined = undefined) {
if (batbotUser === undefined) {
throw new Error("Expected batbotUser to be set");
}
return {
...data,
created_at: created_at || clientTimestamp(),
created_by_id: batbotUser.uid,
created_by_email: batbotEmail,
};
}
const item = createdByBot({
id: "1865_v3.1",
description: "The v3.1 BMS for 1865 cells",
fields: {
version: "v3.1",
cell_format: "1865",
min_voltage: 8,
wired_communication_protocol: "CAN",
screw_sensing: true,
predischarge_current_amps: 0.6,
mosfet_count: 12,
can_ic_model: "TCAN1051H_SOIC",
mosfet_model: "BSC040N08",
esp32_silicon_version: "v3",
can_resistor_model: "TLP170G",
esp32_flash_size_mb: 16,
power_supply_model: "LM5010A",
battery_ic_model: "BQ76952",
shunt_count: 3,
shunt_individual_value_milli_ohms: 2,
fuse_model: "0684L9400-01",
},
})
Also when I use the same script in a staging environment (using a real Firebase instance, and not the emulator) it works just fine
Hi,
I have a bug when using
firebase-emulator, here are some logs and the errorI dumped the protobuf
data.binand downloaded thedata.protofrom the given URL, that I join on this error, here is what happens when I decode it "raw" and with the schemacat data.bin|protoc --decode_rawand with the schema
git clone https://github.com/googleapis/googleapis.git protoc --proto_path=. --proto_path=googleapis --decode=google.events.cloud.firestore.v1.DocumentEventData data.proto < data.binArchive.zip
So it seems I manage to parse the protobuf just fine, not sure why it doesn't work in the code (I have the latest firebase-tools, and all the latest versions of the firebase packages, the "fake test database" that does this bug is created from scratch using a script, so there's no stall data or whatever)
this is the code to generate the data
Also when I use the same script in a staging environment (using a real Firebase instance, and not the emulator) it works just fine