New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling for image loading errors on iOS/Android #849

Merged
merged 10 commits into from Apr 25, 2017

Conversation

Projects
None yet
5 participants
@hartez
Member

hartez commented Mar 30, 2017

Description of Change

  • Prevents the Android and iOS ImageRenderer classes from throwing uncatchable exceptions from async void image loading methods and crashing the application
  • Adds logging for image loading errors to iOS and Android IImageSourceHandler implementations and ImageRenderer classes
  • Provides a mechanism for custom ImageRenderer subclasses to use an alternative error handling method
  • Updates Image.IsLoading when image loading errors occur so it's not left at IsLoading == true forever.
  • Adds automated tests for Image.IsLoading and error logging when image loading errors occur

Bugs Fixed

API Changes

  • Updated the ToString implementations on FileImageSource and UriImageSource to be more informative.

Behavioral Changes

  • The messages logged to the Xamarin.Forms Log class when an image cannot be loaded have changed to be slightly more specific.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense
@rmarinho

This comment has been minimized.

Show comment
Hide comment
@rmarinho

rmarinho Apr 6, 2017

Member

@hartez do you mind rebase please.

Thanks

Member

rmarinho commented Apr 6, 2017

@hartez do you mind rebase please.

Thanks

@rmarinho rmarinho self-requested a review Apr 6, 2017

{
protected override async void Init ()
{
int retry = 5;
while (retry-- >= 0) {
var imageUri = new Uri ("https://xamarin.com/content/images/pages/products/platform.png");
var imageUri = new Uri ("https://raw.githubusercontent.com/xamarin/Xamarin.Forms/master/Xamarin.Forms.ControlGallery.Android/Assets/WebImages/XamarinLogo.png");

This comment has been minimized.

@rmarinho

rmarinho Apr 11, 2017

Member

think this is failing the tests

@rmarinho

rmarinho Apr 11, 2017

Member

think this is failing the tests

This comment has been minimized.

@rmarinho

rmarinho Apr 11, 2017

Member

seems to only happen when there's no cache of the image.

@rmarinho

rmarinho Apr 11, 2017

Member

seems to only happen when there's no cache of the image.

hartez and others added some commits Mar 29, 2017

First run at removing async void image update methods
Consistent error logging and IsLoading on Android,iOS,UWP

Move error logging into image handlers for better messages

Add demo of custom ImageRenderer error handling

Update docs

Make the test smaller so the results don't get pushed offscreen

Fix namespace error
Check disposed on GetDesiredSize for fast renderer
Use local disposed member where possible for disposed check
@rmarinho

Minor comments that could or not be address.. not important stuff to block the pr

Show outdated Hide outdated ...Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
Show outdated Hide outdated Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs
Show outdated Hide outdated Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs
if (_element != null)
_element.PropertyChanged -= OnElementPropertyChanged;
base.Dispose(disposing);

This comment has been minimized.

@rmarinho

rmarinho Apr 21, 2017

Member

If order is important maybe leave a comment

@rmarinho

rmarinho Apr 21, 2017

Member

If order is important maybe leave a comment

protected async Task UpdateBitmap(Image previous = null)
{
if (_element == null || _disposed)

This comment has been minimized.

@rmarinho

rmarinho Apr 21, 2017

Member

i would drop the{ :)

@rmarinho

rmarinho Apr 21, 2017

Member

i would drop the{ :)

@samhouts

Need to turn the linker back on, but looks good otherwise.

Show outdated Hide outdated ...Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
{
// By default we'll just catch and log any exceptions thrown by UpdateBitmap so they don't bring down
// the application; a custom renderer can override this method and handle exceptions from
// UpdateBitmap differently if it wants to

This comment has been minimized.

@samhouts

samhouts Apr 21, 2017

Member

Nice!

@samhouts

@rmarinho rmarinho merged commit cdc4055 into master Apr 25, 2017

5 checks passed

Android-UITests-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Stable - Cycle 9 :: UI Tests :: OSX Test Cloud Package - Run Android 6.0.1 : Tests passe…
Details
Android-UITests-LegacyRenderers Finished TeamCity Build Xamarin.Forms :: Debug :: Stable - Cycle 9 :: UI Tests :: OSX Test Cloud Package - Run Android 6.0.1 (Legacy Rende…
Details
OSX-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Stable - Cycle 9 :: OSX Debug : Running
Details
Windows-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Stable - Cycle 9 :: Windows Debug : Tests passed: 3768, ignored: 10
Details
Windows-Release Finished TeamCity Build Xamarin.Forms :: Debug :: Stable - Cycle 9 :: Windows Release Unit Tests : Tests passed: 3768, ignored: 10
Details

@rmarinho rmarinho deleted the fix-bugzilla51173 branch Apr 26, 2017

@samhouts samhouts added D-15.4 and removed cla-not-required labels Oct 10, 2017

@samhouts samhouts added this to the 2.3.5 milestone Jun 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment