Search code examples
flutteraudioerror-handlingservicesentry

How to monitor errors in audio_service?


How to implement an error monitoring in audio_service?

It runs in isolate, but none of methods available expose Isolate to add error listener. Thus is there any other method for hooking it to error monitoring platform like ex. sentry?


Solution

  • Good news and bad news.

    When the UI isolate is present and initiates the method call to the background isolate, any exception generated by the background task will be forwarded to the UI isolate where you can create an error zone or use something like sentry. For example, an error thrown by onPlay in the background isolate will be forwarded and thrown by play in the main UI isolate.

    However, when the UI isolate is not around, or the media notification initiates the method call to the background isolate, the exception will be caught and discarded internally.

    Making the latter case an uncaught exception would make a good feature request. Although note that the next version of audio_service will run under a single isolate which would also solve the problem.