Flutterfire: [cloud_firestore] Crash if document is given an empty string

Created on 17 Nov 2019  Â·  3Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug
If you give an empty string as id to document it causes the app to crash. Even if wrapped in a try/catch.

To Reproduce
Steps to reproduce the behavior:

myAsyncMethod() async {
      await Firestore.instance.collection('test').document('').get();
}

Causes crash:

*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50b97b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff256c9c2a -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
    4   Runner                              0x000000010b345264 _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 356
    5   Runner                              0x000000010b344aa3 _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3__1<…>
Lost connection to device.

Expected behavior
I would expect to get a Null as return value instead of a crash. Also i'd expect the the error to be caught in a try/catch clause.

Additional context
Testet on an iOS emulator.

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.15.1 19B88, locale en-NO)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.2)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.40.0)
[✓] Connected device (1 available)
customer cloud_firestore bug

Most helpful comment

Hi @iapicca
You might be right, but i would not expect the API to crash that hard on invalid input ( and without proper feedback ). Also i did not expect the crash when in a try/catch clause. It was kind of hard to figure out what caused the crash because of that.

All 3 comments

Hi @erf
I believe your issue is more a proposal than a bug,
since there are many ways to achieve the "safety" you are expecting from the code,
nevertheless you feedback is welcome and certainly can improve
the plugin's usability.
thank you for your contribution

Hi @iapicca
You might be right, but i would not expect the API to crash that hard on invalid input ( and without proper feedback ). Also i did not expect the crash when in a try/catch clause. It was kind of hard to figure out what caused the crash because of that.

Hey all, as part of our on-going work for #2582, this has been resolved in our Firebase Firestore rework (#2913) (validation has been added in Dart to ensure non-empty strings) - which has now been merged into master. We'll look at publishing some prereleases in the next few days. Thank you

Was this page helpful?
0 / 5 - 0 ratings