Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Event without subject makes emulator crash #5803

Closed
BPHvZ opened this issue May 5, 2023 · 5 comments · Fixed by #5819
Closed

Custom Event without subject makes emulator crash #5803

BPHvZ opened this issue May 5, 2023 · 5 comments · Fixed by #5819

Comments

@BPHvZ
Copy link

BPHvZ commented May 5, 2023

Environment info

firebase-tools: 11.30.0

Platform: macOS

Steps to reproduce

  • Use firestore-stripe-payments extension
  • Setup custom events in the extension using eventarc
  • Use Firebase emulator
  • Receive an event without subject in attributes
  • Emulator will crash
  • Log reports error is in getOptionalAttribute in eventarcEmulatorUtils.js

Expected behavior

Emulator should parse the event correctly because subject is optional.

Actual behavior

Emulator crashes because it's unable to parse the event.

Logs
[info] Received custom event at channel projects/tell-the-dj/locations/europe-west4/channels/firebase: {
  "@type": "type.googleapis.com/io.cloudevents.v1.CloudEvent",
  "id": "9e080860-8da2-43fd-a726-f1fe9ff9d2ac",
  "type": "com.stripe.v1.price.updated",
  "specVersion": "1.0",
  "source": "projects/tell-the-dj/instances/firestore-stripe-payments",
  "attributes": {
    "time": {
      "ceTimestamp": "2023-05-05T23:18:23.434Z"
    },
    "datacontenttype": {
      "ceString": "application/json"
    }
  },
  "textData": "{\"id\":\"price_1N4XURBOBLXrmMvIxsRjtdYh\",\"object\":\"price\",\"active\":true,\"billing_scheme\":\"per_unit\",\"created\":1683327159,\"currency\":\"eur\",\"custom_unit_amount\":null,\"livemode\":false,\"lookup_key\":null,\"metadata\":{},\"nickname\":null,\"product\":\"prod_NqDwGZ7f5XsPUY\",\"recurring\":null,\"tax_behavior\":\"unspecified\",\"tiers_mode\":null,\"transform_quantity\":null,\"type\":\"one_time\",\"unit_amount\":102,\"unit_amount_decimal\":\"102\"}"
} {"metadata":{"emulator":{"name":"eventarc"},"message":"Received custom event at channel projects/tell-the-dj/locations/europe-west4/channels/firebase: {\n  \"@type\": \"type.googleapis.com/io.cloudevents.v1.CloudEvent\",\n  \"id\": \"9e080860-8da2-43fd-a726-f1fe9ff9d2ac\",\n  \"type\": \"com.stripe.v1.price.updated\",\n  \"specVersion\": \"1.0\",\n  \"source\": \"projects/tell-the-dj/instances/firestore-stripe-payments\",\n  \"attributes\": {\n    \"time\": {\n      \"ceTimestamp\": \"2023-05-05T23:18:23.434Z\"\n    },\n    \"datacontenttype\": {\n      \"ceString\": \"application/json\"\n    }\n  },\n  \"textData\": \"{\\\"id\\\":\\\"price_1N4XURBOBLXrmMvIxsRjtdYh\\\",\\\"object\\\":\\\"price\\\",\\\"active\\\":true,\\\"billing_scheme\\\":\\\"per_unit\\\",\\\"created\\\":1683327159,\\\"currency\\\":\\\"eur\\\",\\\"custom_unit_amount\\\":null,\\\"livemode\\\":false,\\\"lookup_key\\\":null,\\\"metadata\\\":{},\\\"nickname\\\":null,\\\"product\\\":\\\"prod_NqDwGZ7f5XsPUY\\\",\\\"recurring\\\":null,\\\"tax_behavior\\\":\\\"unspecified\\\",\\\"tiers_mode\\\":null,\\\"transform_quantity\\\":null,\\\"type\\\":\\\"one_time\\\",\\\"unit_amount\\\":102,\\\"unit_amount_decimal\\\":\\\"102\\\"}\"\n}"}}
[debug] [2023-05-05T23:18:23.528Z] TypeError: Cannot read properties of undefined (reading 'ceString')
    at getOptionalAttribute (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulatorUtils.js:39:34)
    at cloudEventFromProtoToJson (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulatorUtils.js:24:18)
    at /Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:93:88
    at Array.map (<anonymous>)
    at EventarcEmulator.triggerCustomEventFunction (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:89:14)
    at publishEventsHandler (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:56:22)
    at Layer.handle [as handle_request] (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/node_modules/express/lib/router/route.js:144:13)
    at IncomingMessage.<anonymous> (/Users/bart/Desktop/SimpleAppsFarm/tell_the_dj_firebase/functions/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:67:17)
    at IncomingMessage.emit (node:events:525:35)
[error] 
[error] Error: An unexpected error has occurred.
@BPHvZ BPHvZ added the type: bug label May 5, 2023
@google-oss-bot
Copy link
Contributor

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@Zambonilli
Copy link

Reproduced this with a custom event published via the firebase-admin/eventarc Channel type. When not setting the subject, the emulator crashes with the same TypeError: Cannot read properties of undefined (reading 'ceString') error. After adding the subject, the eventarc emulator does not crash.

@joehan
Copy link
Contributor

joehan commented Jun 29, 2023

@Zambonilli could you share the debug logs & what version of firebase-tools you are using? I believe this issue is fixed, but its possible that there is somewhere else in the code where we are unsafely accessing 'ceString'

@Zambonilli
Copy link

I'm using firebase-tools version 11.30.0 and below is the stack trace of the crashing error.

[debug] [2023-06-29T19:31:05.121Z] TypeError: Cannot read properties of undefined (reading 'ceString')
    at getOptionalAttribute (/usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulatorUtils.js:39:34)
    at cloudEventFromProtoToJson (/usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulatorUtils.js:24:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:93:88
    at Array.map (<anonymous>)
    at EventarcEmulator.triggerCustomEventFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:89:14)
    at publishEventsHandler (/usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:56:22)
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:144:13)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/emulator/eventarcEmulator.js:67:17)
    at IncomingMessage.emit (node:events:513:28)
[error] 
[error] Error: An unexpected error has occurred.

@joehan
Copy link
Contributor

joehan commented Jun 29, 2023

Ahhh - the fix for this went out in 12.0.1, so you'll need to upgrade to get it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants