flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

errorWidget seems to leak exceptions occasionally

Open larssn opened this issue 3 years ago • 8 comments

🐛 Bug Report

I keep getting http exceptions in my debug console and error reporting service (Sentry), which shouldn't happen as I use the errorWidget builder. The exceptions look like this:

I/flutter (14804): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (14804): The following HttpExceptionWithStatus was thrown resolving an image codec:
I/flutter (14804): HttpException: Invalid statusCode: 403, uri = <redacted>
I/flutter (14804):
I/flutter (14804): When the exception was thrown, this was the stack
I/flutter (14804):
I/flutter (14804): Image provider:
I/flutter (14804): CachedNetworkImageProvider("<redacted>",
I/flutter (14804): scale: 1.0)
I/flutter (14804):  Image key:
I/flutter (14804): CachedNetworkImageProvider("<redacted>",
I/flutter (14804): scale: 1.0):
I/flutter (14804):   CachedNetworkImageProvider("<redacted>",
I/flutter (14804):   scale: 1.0)
I/flutter (14804): ════════════════════════════════════════════════════════════════════════════════════════════════════

The widget is used like this:

final uri = "https://firebasestorage.googleapis.com/v0/b/test-proj.appspot.com/o/broken.png?alt=media&token=b89f711d-c90d-46ed-84c8-123456789";

CachedNetworkImage(
      imageUrl: uri,
      errorWidget: (context, url, error) => const Padding(
        padding: EdgeInsets.all(8.0),
        child: Icon(Icons.broken_image_outlined),
      ),
      imageBuilder: (context, imageProvider) {
        return Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: CachedNetworkImageProvider(uri),
              fit: BoxFit.cover,
            ),
            color: Theme.of(context).cardTheme.color,
          ),
        );
      },
    );
  }

And it does as expected: It shows the Icons.broken_image_outlined for images that can't be loaded, like for example, the image that causes the exception above.

Expected behavior

I expect no exceptions to leak when the plugin seems to do what is expected.

Reproduction steps

Not sure, there's never any stack trace attached to the above exception, and as mentioned the actual behavior of the widget seems correct.

Configuration

Version: 3.2.1

Platform:

  • [ ] :iphone: iOS (maybe)
  • [x] :robot: Android

larssn avatar Sep 12 '22 17:09 larssn

having same issue any solution

vishalpatel1327 avatar Nov 07 '22 06:11 vishalpatel1327

Seeing this as well for 403 errors and empty URLs. Any leads/fixes for this would be fantastic!

knyghtryda avatar Nov 08 '22 04:11 knyghtryda

I also got the same issue with android using error builder but also got exception. Widget is working perfectly but exception should not thrown when we use error builder.

faheem-riaz avatar Nov 19 '22 14:11 faheem-riaz

Also happening on iOS and for many Http error codes such as 500

LuisMiguelSS avatar Nov 28 '22 14:11 LuisMiguelSS

Looks like #777 fixes it

LuisMiguelSS avatar Dec 14 '22 15:12 LuisMiguelSS

Looks like #777 fixes it

That's a PR for an error listener, which is when you wish to react to errors in a non-widget kinda way. It most likely won't fix this, but probably a welcome feature none the less.

larssn avatar Dec 15 '22 08:12 larssn