Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.4k stars 631 forks source link

Bugfix: Change how errors are reported by ImageLoader. Emits as stream instead of re-throwing #937

Open robert-northmind opened 1 month ago

robert-northmind commented 1 month ago

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

This is a bug fix

:arrow_heading_down: What is the current behavior?

If the CachedNetworkImageProvider gets some error when fetching an image url, then internally the ImageLoader will rethrow that error. This leads to the unwanted behavior that you get an uncaught exception. And this for example then leads to faulty fatal errors being reported in Crashlytics.

:new: What is the new behavior (if this is a feature change)?

Instead of throwing the error inside the ImageLoader, we are now emitting the error as a stream error into the current stream. This has the added benefit that this will not be an uncaught exception. And all existing ErrorListeners, ErrorBuilders will still work.

:boom: Does this PR introduce a breaking change?

No

:bug: Recommendations for testing

You can test this change with the existing example app. If you run the example app for a mobile device and enabled the debugger to catch uncaught exceptions, then with this fix you will not get any uncaught exceptions. And before this fix, you would get uncaught exceptions for the https://notAvalid.uri and the not a uri at all.

:memo: Links to relevant issues/docs

N/A

:thinking: Checklist before submitting

Screenshots

These screenshots come from VSCode running the previous version with uncaught exceptions turned on:

Screenshot 2024-04-10 at 15 16 51 Screenshot 2024-04-10 at 15 16 57

And here is a screenshot coming from this version with uncaught exceptions turned on:

Screenshot 2024-04-10 at 15 16 14