Skip to content

withAuthContext firestore functions cause error in emulator #7037

Closed

Description

@Bullfrog1234

Related issues

No related issues found.
The capability was added through the firebase/firebase-functions#1519
 

[REQUIRED] Version info

node: v20.11.0

firebase-functions: v4.9.0

firebase-tools: v13.7.2

firebase-admin: v12.0.0

[REQUIRED] Test case

  1. Create a new event trigger function for onDocumentCreatedWithAuthContext
  2. Build the code if using typescript
  3. Run the emulators
  4. Watch it fail to run the emulators

The error returned from firebase-tools is:

[warn] !  Unexpected rules runtime error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "line" is null
	at com.google.firebase.rules.tools.local.server.Server.processRequestsFromInputStream(Server.java:75)
	at com.google.firebase.rules.tools.local.server.Server.start(Server.java:57)
	at com.google.firebase.rules.tools.local.FirebaseRulesTooling.main(FirebaseRulesTooling.java:81)
 {"metadata":{"emulator":{"name":"storage"},"message":"Unexpected rules runtime error: Exception in thread \"main\" java.lang.NullPointerException: Cannot invoke \"String.length()\" because \"line\" is null\r\n\tat com.google.firebase.rules.tools.local.server.Server.processRequestsFromInputStream(Server.java:75)\r\n\tat com.google.firebase.rules.tools.local.server.Server.start(Server.java:57)\r\n\tat com.google.firebase.rules.tools.local.FirebaseRulesTooling.main(FirebaseRulesTooling.java:81)\r\n"}}
[info] i  logging: Stopping Logging Emulator {"metadata":{"emulator":{"name":"logging"},"message":"Stopping Logging Emulator"}}
[error] 
[error] Error: HTTP Error: 500, [object Object]
[debug] [2024-04-13T13:44:30.399Z] Error Context: {
  "body": {
    "error": {
      "code": 500,
      "status": "UNKNOWN"
    }
  },
  "response": {
    "statusCode": 500
  }
}

Inspecting the java error shows the issue:

 Unsupported eventType: google.cloud.firestore.document.v1.created.withAuthContext; Supported ones: [google.cloud.firestore.document.v1.created, google.cloud.firestore.document.v1.deleted, google.cloud.firestore.document.v1.updated, google.cloud.firestore.document.v1.written]

[REQUIRED] Steps to reproduce

As above

[REQUIRED] Expected behavior

Either:

  • Warning in the emulator output that it is not supported and not load it and continue with emulating the rest
  • Emulate the new Firestore triggers (Preferred)

[REQUIRED] Actual behavior

Errors are returned on emulator start. Have to disable new functions to get emulators to run.

Were you able to successfully deploy your functions?

Not relevant to this error as it relates to the emulators

Activity

  1. google-oss-bot commented on Apr 13, 2024

    @google-oss-bot
    Collaborator

    I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

  2. Bullfrog1234 commented on Apr 13, 2024

    @Bullfrog1234
    Author

    This could also be an issue for firebase tools. Not sure. If so let me know and will raise it there.

  3. benomatis commented on Apr 21, 2024

    @benomatis

    I get the same error, despite importing the trigger like this:

    import { onDocumentWrittenWithAuthContext } from 'firebase-functions/v2/firestore'

    I get the following error

    java.lang.IllegalArgumentException: Unsupported eventType: google.cloud.firestore.document.v1.written.withAuthContext; Supported ones: [google.cloud.firestore.document.v1.created, google.cloud.firestore.document.v1.deleted, google.cloud.firestore.document.v1.updated, google.cloud.firestore.document.v1.written]

    For some reason it is trying to use Google Cloud Firestore triggers instead of Firebase Functions Firestore triggers despite the fact it's how it's been imported.

    And I can confirm this is definitely an emulator problem only, the function otherwise deploys fine.

  4. self-assigned this
    on Apr 22, 2024
  5. blidd-google commented on Apr 24, 2024

    @blidd-google
    Contributor

    Hi all, I've flagged the issue to the Firestore team and we should have support for the new auth context event types in the next release. Will update this thread once we've released support. Thanks for your patience!

  6. Bullfrog1234 commented on May 5, 2024

    @Bullfrog1234
    Author

    Any news on the timeline for this?

  7. joehan commented on May 7, 2024

    @joehan
    Member

    @Bullfrog1234 This is in the works, we discovered some issues with our initial implementation that we're currently addressing. Unfortunately, due to upcoming code freezes for Google I/O, this will probably be a few more weeks we're able to ship it.

  8. Bullfrog1234 commented on May 8, 2024

    @Bullfrog1234
    Author

    @joehan Thanks for the update and understood about code freeze.

  9. Seanitzel commented on May 20, 2024

    @Seanitzel

    Would be great if you can put a note about it in the docs in the meantime, to save people's time :)

  10. lukebordonaro commented on May 28, 2024

    @lukebordonaro

    Is there an ETA for when a release will be out? My use-case for wanting this support is I want to write unit tests for the functions that use Firebase Emulator (e.g. firebase emulators:exec --only firestore,functions "npm run test:functions"). Unfortunately, that's not possible if the emulator can't start ☹️

  11. benbrunyee commented on May 28, 2024

    @benbrunyee

    Are there any suggested alternatives for the time being?
    Local development for my web app is paused until firebase emulators:start works.

  12. bytewiz commented on May 28, 2024

    @bytewiz

    Same issue here using onDocumentWrittenWithAuthContext

  13. Bullfrog1234 commented on Jun 1, 2024

    @Bullfrog1234
    Author

    Hi @joehan,

    I assume the code freeze is completed, so I am wishing for an update on this.

    If the timeline is greater than 2 weeks from today can we follow @Seanitzel suggestion and add a note to the documentation. This will inform uses that this is not working in the emulators until it is fixed.

  14. ohld commented on Jul 29, 2024

    @ohld

    Hi @Bullfrog1234,

    I still have the same issue once I add a new function that uses onDocumentWrittenWithAuthContext. My firebase-tools --version version is 13.14.2.

    When I run the emulators I see in the logs that firestore emulator is downgraded from 1.19.7 back to 1.19.6 which doesn't have a fix.

    startups-functions:serve: i  emulators: Starting emulators: functions, firestore
    startups-functions:serve: ⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub, storage, dataconnect
    startups-functions:serve: i  firestore: downloading cloud-firestore-emulator-v1.19.6.jar...
    Progress: ===========================================================================> (100% of 67MB)
    startups-functions:serve: i  firestore: Removing outdated emulator files: cloud-firestore-emulator-v1.19.7.jar```
    

    UPD:

    Resolved by updating firebase-tools package manually in all package.json files in the project.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions