Skip to content

Non-nil empty strings cause Firestore to crash instead of throwing an error gracefully #8218

Closed
@Sam-Spencer

Description

@Sam-Spencer

Environment

  • Xcode version: 12.5
  • Firebase SDK version: 8.0.0
  • Installation method: Swift Package Manager
  • Firebase Component: Firestore

The Problem

Currently, attempting a Firestore document load (of any nature) with an empty ID causes a runtime exception which results in a crash. By "empty ID" I am referring to a string whose character count is zero, but where the object is non-nil. Literally, an empty string.

While Firestore handles a number of errors and returns the failure results gracefully in many cases, this is not one of those. It would be nice if the SDK could catch this and return an error

Steps to reproduce:

  1. Start in a Swift environment
  2. Create a Firestore document or collection request
  3. In the document ID parameter: .document(ID), supply a non-nil but empty string such as "".
  4. Firestore throws a fatal error and causes the application to crash.
  5. Crash logs are difficult to parse, as the throw occurs deep inside the Firestore core framework.

Relevant Code

It appears, from crash logs that this occurs deep in the Firestore framework (core/src/api/collection_reference.cc):

return DocumentReference(std::move(path), firestore());

There seems to be an attempt to handle the issue and fail gracefully in Source/API/FIRCollectionReference.mm):

- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath { if (!documentPath) { ThrowInvalidArgument("Document path cannot be nil."); } DocumentReference child = self.reference.Document(util::MakeString(documentPath)); return [[FIRDocumentReference alloc] initWithReference:std::move(child)]; }

Unfortunately, if(!documentPath) does not handle cases where strings may be non-nil, yet still empty (something I think may have been made possible in a recent Swift release 🥴?).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    close