Flutterfire: Cloud Firestore crashes natively on DocumentReference.get()

Created on 19 Feb 2020  Â·  3Comments  Â·  Source: FirebaseExtended/flutterfire

This is an issue that comes up rarely, but consistently.
I make a CollectionReference, and get a DocumentReference from it, and then call .get() on the DocumentReference. Getting the CollectionReference and DocumentReference works just fine, but the app crashes natively when .get() is called. The DocumentReference points to a real document in the database. My code is as follows

CollectionReference usersCollection = _fireStore.collection(_usersCollection);
    print("Created users collection reference");
    DocumentReference userDoc = usersCollection.document(uid);
    print("Created user's document reference");
    DocumentSnapshot usr = await userDoc.get();
    print("Data retrieved");`
The debug output is
`flutter: Created users collection reference
flutter: Created user's document reference
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff256e9c1a -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
    4   Runner                              0x000000010d402bd4 _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 356
    5   Runner                              0x000000010d402413 _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3__<…>
Lost connection to device.

Output of flutter doctor:
`[✓] Flutter (Channel master, v1.15.4-pre.83, on Mac OS X 10.15.3 19D76, locale
en-US)
• Flutter version 1.15.4-pre.83 at /Users/OwenScott/devtools/flutter
• Framework revision ec9813a500 (2 days ago), 2020-02-16 19:15:52 -0800
• Engine revision d60f298d9e
• Dart version 2.8.0 (build 2.8.0-dev.9.0 edd64e6d5c)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/OwenScott/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.0.beta.2

[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Community Edition (version 2019.3.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 43.0.3
• Dart plugin version 193.6494.35

[✓] VS Code (version 1.40.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.6.0

[✓] Connected device (1 available)
• iPhone 11 Pro Max • 4CE40E91-D69E-4A87-B150-A865C351FEB3 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!
`

crowd cloud_firestore bug

Most helpful comment

Note: I have discovered the steps to reproduce
Call .get() on a DocumentReference with an empty document id, ie
await Firestore.instance.collection("MyCollection").document("").get();
I understand why this happens and that this can simply be avoided by String validation before the .document() method is called, but it would still be better to return an error message natively and throw an exception at the Dart / Flutter level so that the app doesn't crash egregiously without any clear reason.

All 3 comments

Note: I have discovered the steps to reproduce
Call .get() on a DocumentReference with an empty document id, ie
await Firestore.instance.collection("MyCollection").document("").get();
I understand why this happens and that this can simply be avoided by String validation before the .document() method is called, but it would still be better to return an error message natively and throw an exception at the Dart / Flutter level so that the app doesn't crash egregiously without any clear reason.

This was flagged in another issue and needs fixing/validation, however doing .document("") is invalid since you can't query an "empty" document.

Was this page helpful?
0 / 5 - 0 ratings