SunnyApp / flutter_contact

A flutter plugin for retrieving, creating, saving, and watching contacts on native devices
BSD 3-Clause "New" or "Revised" License
81 stars 62 forks source link

Error reporting on unexpected format of the contact data #32

Closed suztomo closed 3 years ago

suztomo commented 4 years ago

When thinking about https://github.com/SunnyApp/flutter_contact/issues/31, this library treats the unexpected data as null. I dug the source code and identified that it was value key that was unexpected to this library when I use BlackBerry Priv (Android 6.0.1). This can be fixed by checking the value key in the map in addition to existing date key.

However, this fix only applies to the devices that return value and date for the dates. There could be other type of devices that return data in a different format. If I'm lucky, my user who suffer from the glitch would communicate to me about the glitch and I happen to have the same device as them to debug further to find the unexpected data. It's very unlikely.

I need a way to troubleshoot the unexpected data from my users' devices, without requiring them a special effort. Here are few options I thought of:

Option 1: Throw an exception upon unexpected data

Currently it return null for unexpected date map (see the screenshot in #31). I thought about throwing an exception rather than returning null. I can catch the exception from the library and send some message to me via Firebase Crashlytics.

However, this option might crash apps that use this library, even when the unexpected data is unused. Furthermore, one unexpected data prevents a user of app from listing contacts.

Option 2: Add a handler for unexpected data

How about this library taking a handler for error reporting on unexpected format of the contract data? I have an opportunity to report error while the library continue to work only except the unexpected data..

The idea is when initializing ContactService in this library, it would optionally take a handler (a function) with type void Function(Exception unexpectedDataException). When this library hits an unexpected data, it calls the handler and continues processing next data. I would pass a call to Firebase Crashlytics. This way, the library continues to work for users and I can get understanding of unexpected format of users data and devices.

final ContactService _contactService = UnifiedContacts(errorReporting: (Exception exception) {
    try {
      throw exception;
    } on Exception catch (error, stacktrace) {
      FirebaseCrashlytics.instance.recordError(error, stacktrace);
    }
  })
ericmartineau commented 3 years ago

The problem with dates was a bug in the library that's been fixed, but I did add a few things in this direction:

suztomo commented 3 years ago

Thank you.