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

Firestore crashing withFIRQueryDocumentSnapshot . #4271

Closed
RuiAAPeres opened this issue Nov 8, 2019 · 3 comments
Closed

Firestore crashing withFIRQueryDocumentSnapshot . #4271

RuiAAPeres opened this issue Nov 8, 2019 · 3 comments

Comments

@RuiAAPeres
Copy link

RuiAAPeres commented Nov 8, 2019

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Xcode version: Xcode 11.2
  • Firebase SDK version: 6.12.0
  • Firebase Component: Firestore
  • Component version: 1.7.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I am doing a simple query to Firestore and getting a runtime crash:

Precondition failed: NSArray element failed to match the Swift Array Element type
Expected FIRQueryDocumentSnapshot but found FIRQueryDocumentSnapshot: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.274.2/swift/stdlib/public/core/ArrayBuffer.swift, line 354
2019-11-08 17:14:26.097113+0000 App[40195:45138882] Precondition failed: NSArray element failed to match the Swift Array Element type
Expected FIRQueryDocumentSnapshot but found FIRQueryDocumentSnapshot: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.274.2/swift/stdlib/public/core/ArrayBuffer.swift, line 354

Relevant Code:

          store
            .collection(ChatReadingService.Collection.conversations)
            .document(id)
            .collection(ChatReadingService.Collection.messages)
            .order(by: ChatReadingService.Field.createdAt, descending: true)
            .limit(to: 1)
            .addSnapshotListener { (snapshot: QuerySnapshot?, error: Error?) in
             
             guard error == nil else {
                return
              }
              
              guard let unwrapped = snapshot else {
                return
              }
              
              let documents: [MyEntity] = unwrapped.documents.compactMap { (value: QueryDocumentSnapshot) in
                return try? value.data(as: MyEntity.self)
              }

           }

The crash is happening at unwrapped.documents.

@RuiAAPeres RuiAAPeres changed the title FireStore crashing withFIRQueryDocumentSnapshot . Firestore crashing withFIRQueryDocumentSnapshot . Nov 8, 2019
@mikelehen
Copy link
Contributor

Hrm. From the error I am wondering if you're somehow getting two different definitions of FIRQueryDocumentSnapshot in your app. Can you maybe try clearing your Pods directory and Podfile.lock, and running "pod install" fresh? And if you still see the error can you share your Podfile.lock file?

@RuiAAPeres
Copy link
Author

Hi @mikelehen! In fact those two issues are related. I was linking Firebase in multiple internal frameworks that I have. I think it would be advisable (unless I missed it completely), to put a warning in the documentation.

@mikelehen
Copy link
Contributor

@RuiAAPeres Thanks for following up! It sounds like this issue is resolved so I'm going to go ahead and close it.

That said I'm happy to try to get the docs improved to help out future folks. Do you happen to have any suggestion of where we could document this so that you would have seen it? I'm not sure how common it is for people to run into this and where we can best document it, but I can follow up with docs folks to see what we can do. cc/ @paulb777 @ryanwilson

@firebase firebase locked and limited conversation to collaborators Dec 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants