Baseflow / flutter_cached_network_image

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

CacheManager: Failed to download file from url #336

Open sandeep9607 opened 4 years ago

sandeep9607 commented 4 years ago

cached_network_image: ^2.0.0

I/flutter (23961): CacheManager: Failed to download file from http://host/images/a.png with error: I/flutter (23961): SocketException: Failed host lookup: 'host' (OS Error: No address associated with hostname, errno = 7)

suragch commented 3 years ago

For others coming here, you may be mistaking the IDE debugger stopping on the exception as the CachedNetworkImage not working by showing the errorWidget. That's what I thought. However, you can press the continue button or turn off the "Uncaught exceptions" breakpoint and the errorWidget will still show. See issue #467 and my Stack Overflow Q&A:

https://stackoverflow.com/questions/65732967/flutter-cachednetworkimage-errors-cachemanager-failed-to-download-file-and/65732968

renefloor commented 3 years ago

@suragch thanks for your answer, I included in a newly made FAQ: https://github.com/Baseflow/flutter_cached_network_image/commit/d4b09daf3442902afa49976c19ba9adf51f292e8

MerendaFrancoN commented 3 years ago

Hi ! I have a carousel that had this error, and when one of the image was failing, all the others failed. So I solved it enforcing each CachedNetworkImage() with UniqueKey(), so flutter has each widget uniquely identified. I hope it helps!

MohamedCharaabi commented 3 years ago

I used to have the same issue! If you have a break on exceptions enabled the debugger stops, but that's because the dart VM doesn't always know whether an exception is caught or not. If you continue this still shouldn't freeze your app.

d4KN9 qZmY1
sandeep9607 commented 3 years ago

Screenshot 2021-05-04 at 10 58 42 AM crashalitics also catch this issue. @renefloor there is something really weired

renefloor commented 3 years ago

No host specified means the url didn't start with http(s)://. Do you have any idea what the url could have been?

cached_network_image: ^2.0.0

I/flutter (23961): CacheManager: Failed to download file from http://host/images/a.png with error: I/flutter (23961): SocketException: Failed host lookup: 'host' (OS Error: No address associated with hostname, errno = 7)

In your original post you did have 'http', but you had an invalid hostname 'host'.

sandeep9607 commented 3 years ago

It's for example.but it happends for all Images @renefloor

sandeep9607 commented 3 years ago

2021-05-09 14:09:46.585635+0530 Runner[5713:2950075] flutter: CacheManager: Failed to download file from with error: Invalid argument(s): No host specified in URI 2021-05-09 14:09:46.600427+0530 Runner[5713:2950075] flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ 2021-05-09 14:09:46.600546+0530 Runner[5713:2950075] flutter: The following ArgumentError was thrown resolving an image codec: 2021-05-09 14:09:46.600590+0530 Runner[5713:2950075] flutter: Invalid argument(s): No host specified in URI 2021-05-09 14:09:46.600622+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.600660+0530 Runner[5713:2950075] flutter: When the exception was thrown, this was the stack: 2021-05-09 14:09:46.600700+0530 Runner[5713:2950075] flutter: #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2407:9) 2021-05-09 14:09:46.600732+0530 Runner[5713:2950075] flutter: #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2323:7) 2021-05-09 14:09:46.600761+0530 Runner[5713:2950075] flutter: #2 IOClient.send (package:http/src/io_client.dart:31:37) 2021-05-09 14:09:46.600975+0530 Runner[5713:2950075] flutter: #3 HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:33:44) 2021-05-09 14:09:46.601076+0530 Runner[5713:2950075] flutter: #4 WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:106:24) 2021-05-09 14:09:46.601673+0530 Runner[5713:2950075] flutter: #5 WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:91:28) 2021-05-09 14:09:46.601903+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.602097+0530 Runner[5713:2950075] flutter: #6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:14) 2021-05-09 14:09:46.602234+0530 Runner[5713:2950075] flutter: #7 WebHelper.downloadFile (package:flutter_cache_manager/src/web/web_helper.dart:44:17) 2021-05-09 14:09:46.602398+0530 Runner[5713:2950075] flutter: #8 CacheManager._pushFileToStream (package:flutter_cache_manager/src/cache_manager.dart:144:27) 2021-05-09 14:09:46.602555+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.602707+0530 Runner[5713:2950075] flutter: #9 CacheManager.getFileStream (package:flutter_cache_manager/src/cache_manager.dart:122:5) 2021-05-09 14:09:46.602878+0530 Runner[5713:2950075] flutter: #10 ImageCacheManager.getImageFile (package:flutter_cache_manager/src/cache_managers/image_cache_manager.dart:27:14) 2021-05-09 14:09:46.603055+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.603269+0530 Runner[5713:2950075] flutter: #11 CachedNetworkImageProvider._loadAsync (package:cached_network_image/src/image_provider/_image_provider_io.dart:99:18) 2021-05-09 14:09:46.603508+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.603690+0530 Runner[5713:2950075] flutter: #12 CachedNetworkImageProvider.load (package:cached_network_image/src/image_provider/_image_provider_io.dart:71:14) 2021-05-09 14:09:46.603855+0530 Runner[5713:2950075] flutter: #13 ImageProvider.resolveStreamForKey. (package:flutter/src/painting/image_provider.dart:504:13) 2021-05-09 14:09:46.604054+0530 Runner[5713:2950075] flutter: #14 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:355:22) 2021-05-09 14:09:46.604229+0530 Runner[5713:2950075] flutter: #15 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:502:83) 2021-05-09 14:09:46.604456+0530 Runner[5713:2950075] flutter: #16 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19) 2021-05-09 14:09:46.604626+0530 Runner[5713:2950075] flutter: #17 ImageProvider.resolve. (package:flutter/src/painting/image_provider.dart:333:9) 2021-05-09 14:09:46.604758+0530 Runner[5713:2950075] flutter: #18 ImageProvider._createErrorHandlerAndKey.. (package:flutter/src/painting/image_provider.dart:463:26) 2021-05-09 14:09:46.604951+0530 Runner[5713:2950075] flutter: #19 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:41:35) 2021-05-09 14:09:46.605136+0530 Runner[5713:2950075] flutter: #20 ImageProvider._createErrorHandlerAndKey. (package:flutter/src/painting/image_provider.dart:460:11) 2021-05-09 14:09:46.605371+0530 Runner[5713:2950075] flutter: #24 ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:452:16) 2021-05-09 14:09:46.605559+0530 Runner[5713:2950075] flutter: #25 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:330:5) 2021-05-09 14:09:46.605751+0530 Runner[5713:2950075] flutter: #26 _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1156:16) 2021-05-09 14:09:46.606014+0530 Runner[5713:2950075] flutter: #27 _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:1109:5) 2021-05-09 14:09:46.606543+0530 Runner[5713:2950075] flutter: #28 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4797:14) 2021-05-09 14:09:46.606582+0530 Runner[5713:2950075] flutter: #29 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) 2021-05-09 14:09:46.606614+0530 Runner[5713:2950075] flutter: #30 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33) 2021-05-09 14:09:46.606647+0530 Runner[5713:2950075] flutter: #31 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:913:20) 2021-05-09 14:09:46.606709+0530 Runner[5713:2950075] flutter: #32 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5) 2021-05-09 14:09:46.606824+0530 Runner[5713:2950075] flutter: #33 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15) 2021-05-09 14:09:46.606942+0530 Runner[5713:2950075] flutter: #34 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9) 2021-05-09 14:09:46.607115+0530 Runner[5713:2950075] flutter: #35 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5) 2021-05-09 14:09:46.607307+0530 Runner[5713:2950075] flutter: #39 _invoke (dart:ui/hooks.dart:251:10) 2021-05-09 14:09:46.607642+0530 Runner[5713:2950075] flutter: #40 _drawFrame (dart:ui/hooks.dart:209:3) 2021-05-09 14:09:46.607856+0530 Runner[5713:2950075] flutter: (elided 6 frames from dart:async) 2021-05-09 14:09:46.608033+0530 Runner[5713:2950075] flutter: 2021-05-09 14:09:46.608175+0530 Runner[5713:2950075] flutter: Image provider: CachedNetworkImageProvider("", scale: 1.0) 2021-05-09 14:09:46.608291+0530 Runner[5713:2950075] flutter: Image key: CachedNetworkImageProvider("", scale: 1.0): 2021-05-09 14:09:46.608428+0530 Runner[5713:2950075] flutter: CachedNetworkImageProvider("", scale: 1.0)

sandeep9607 commented 3 years ago

Valid url @renefloor https://hd.tudocdn.net/874944?w=646&h=284

sandeep9607 commented 3 years ago

I/flutter (17973): I/flutter (17973): Image provider: CachedNetworkImageProvider("", scale: 1.0) I/flutter (17973): Image key: CachedNetworkImageProvider("", scale: 1.0): I/flutter (17973): CachedNetworkImageProvider("", scale: 1.0) I/flutter (17973): ════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by image resource service ════════════════════════════ The following ArgumentError was thrown resolving an image codec: Invalid argument(s): No host specified in URI

When the exception was thrown, this was the stack

0 _HttpClient._openUrl (dart:_http/http_impl.dart:2407:9)

1 _HttpClient.openUrl (dart:_http/http_impl.dart:2323:7)

2 IOClient.send

package:http/src/io_client.dart:31

3 HttpFileService.get

package:flutter_cache_manager/…/web/file_service.dart:33

4 WebHelper._download

package:flutter_cache_manager/…/web/web_helper.dart:106 ... Image provider: CachedNetworkImageProvider("", scale: 1.0) Image key: CachedNetworkImageProvider("", scale: 1.0): CachedNetworkImageProvider("", scale: 1.0) ════════════════════════════════════════════════════════════════════════════════ URl not loading is: https://firebasestorage.googleapis.com/v0/b/mesocialmobile.appspot.com/o/user%2FN2q4tIWzRqa460xsHcbusPMtq4x2%2FprofileImage%2F952651d0-a026-11eb-bee4-438e4c3ebe8a.jpg?alt=media&token=681da556-540c-40ae-98a1-6a968ab24fdf

sandeep9607 commented 3 years ago

2021-05-10 11:09:52.935491+0530 Runner[6333:3213281] flutter: Image provider: CachedNetworkImageProvider("", scale: 1.0) 2021-05-10 11:09:52.935514+0530 Runner[6333:3213281] flutter: Image key: CachedNetworkImageProvider("", scale: 1.0): 2021-05-10 11:09:52.935535+0530 Runner[6333:3213281] flutter: CachedNetworkImageProvider("", scale: 1.0) 2021-05-10 11:09:52.935559+0530 Runner[6333:3213281] flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════ 2021-05-10 11:09:53.657355+0530 Runner[6333:3213281] flutter: CacheManager: Failed to download file from with error: Invalid argument(s): No host specified in URI

@renefloor it work first time perfectly, but second time it suck, it crash iOS version, while android is able to survive.

sourabhmahale commented 3 years ago

In my case, I am passing the null value to imgurl that's why the problem occurs. If you have a problem, just print the URL if it is null or not & then provide a proxy image URL to check it's working to not.

themartorana commented 3 years ago

Hi. I don't want to turn off uncaught exceptions in my IDE. It helps me catch runtime errors. This widget constantly breaking on uncaught exceptions is problematic for development.

kamleshwebtech commented 3 years ago

How can we show a placeholder image, if application is failed or not able to fetch image content from server? Kindly suggest. Thanks.

renefloor commented 3 years ago

How can we show a placeholder image, if application is failed or not able to fetch image content from server? Kindly suggest. Thanks.

By setting the placeholder as errorWidget:

CachedNetworkImage(
  imageUrl: "http://via.placeholder.com/200x150",
  imageBuilder: (context, imageProvider) => Container(
    decoration: BoxDecoration(
      image: DecorationImage(
          image: imageProvider,
          fit: BoxFit.cover,
          colorFilter:
              ColorFilter.mode(Colors.red, BlendMode.colorBurn)),
    ),
  ),
  placeholder: (context, url) => CircularProgressIndicator(),
  errorWidget: (context, url, error) => CircularProgressIndicator(),
),

You can also only set the placeholder and not the errorWidget, in that case the placeholder will be used as errorWidget.

abdullah432 commented 3 years ago

Same issue

batuhankrbb commented 2 years ago

Same issue here

opage commented 2 years ago

Same issue :(

b-cancel commented 2 years ago

Hey @renefloor ! First of all thanks to you and your team for such a fantastic plugin!

but I was thinking... if this issue is so prevalent that the team has had to add a "notice" on the plugin page and since y'all also manage the plugin that is throwing the "error" that isn't wrapped in a try catch

Why not just wrap

throw HttpExceptionWithStatus(
        response.statusCode,
        'Invalid statusCode: ${response.statusCode}',
        uri: Uri.parse(cacheObject.url),
);

within the "web_helper.dart" file in the "flutter_cache_manager" plugin with a try catch?

That would eliminate the need for you too clarify, constantly be bothered by notifications here, and as a bonus, we could develop without worrying about something that isn't actually breaking anything without having to turn off tools that we use every day

darmawan01 commented 2 years ago

same issues here, is there any way to solve it ?

renefloor commented 2 years ago

@b-cancel because the ImageProvider has to return an image or an exception. If we catch the exception, what will we return? A never ending loading indicator?

TylerByte666 commented 2 years ago

@b-cancel because the ImageProvider has to return an image or an exception. If we catch the exception, what will we return? A never ending loading indicator?

That is what you are currently telling us to do with this https://github.com/Baseflow/flutter_cached_network_image/issues/336#issuecomment-862182001 😕 You are literally making it load indefinitely on an error. 😢

In my case. I have an jwt protected route that needs a valid auth header. Your plugin does not give control on when to flush CacheManager? Because my luck means that once I am renewing the user's token, your plugin wants to re-download the image resulting in a 401:

flutter: CacheManager: Failed to download file from https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png with error:
HttpException: Invalid statusCode: 401, uri = https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png

Which means I need to change my list from a Stream to a Future or else this error will constantly pop up 😿

Can we not just do a silent retry? And after a certain amount of attempts can then throw the error, just in case that the internet had a bit of an issue or the server was a bit busy....

suragch commented 2 years ago

@nehal076

FIX IT !

That's not an appropriate comment for an open source repository. Let's be respectful of the maintainers' time and work that they provide freely to us. If something isn't working, we can help by researching the root cause ourselves and proposing a solution.

nehal076 commented 2 years ago

@nehal076

FIX IT !

That's not an appropriate comment for an open source repository. Let's be respectful of the maintainers' time and work that they provide freely to us. If something isn't working, we can help by researching the root cause ourselves and proposing a solution.

Okay, I apologize for my comment.

renefloor commented 2 years ago

@TylerByte666

That is what you are currently telling us to do with this #336 (comment) 😕 You are literally making it load indefinitely on an error. 😢

Not completely sure what you mean here, but it doesn't load indefinitely, it just shows a placeholder instead of the image. When it has an error it stops loading.

In my case. I have an jwt protected route that needs a valid auth header. Your plugin does not give control on when to flush CacheManager? Because my luck means that once I am renewing the user's token, your plugin wants to re-download the image resulting in a 401:

flutter: CacheManager: Failed to download file from https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png with error:
HttpException: Invalid statusCode: 401, uri = https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png

Which means I need to change my list from a Stream to a Future or else this error will constantly pop up 😿

Can we not just do a silent retry? And after a certain amount of attempts can then throw the error, just in case that the internet had a bit of an issue or the server was a bit busy....

Here I also not fully sure what the problem is. Is it that you don't really get the exception in the app because it can still load the cached version? What exactly did you change from a Stream to a Future? You can always provide headers so it can download the file if needed.

TylerByte666 commented 2 years ago

No what I mean is sometimes the image failes to load completely. I then get the exception output as above and vscode will do its normal breaks.

It hasn't happened in a while so I can only imagine it may be internet related. It was a list of users one of which did not have a cached image so when my user list(this is the stream) loaded in the list for the first time I got that error.

Thus my suggestion for a silent retry, which I was able to do in my app by wrapping the code in a try catch and then retracing on that error once or twice after a 30 sec timeout.

I already use the headers, with my bearer token but for some reason I got this error when my token was refreshing as well... I have to make a request to our backend to refresh the token(after an hour or so) and replace the one sent to your plugin. So that kinda blew a hole in my its the internet problem causing it. I will try see if it returns and try provide more info.

On Tue, 02 Nov 2021, 10:39 Rene Floor, @.***> wrote:

@TylerByte666 https://github.com/TylerByte666

That is what you are currently telling us to do with this #336 (comment) https://github.com/Baseflow/flutter_cached_network_image/issues/336#issuecomment-862182001 😕 You are literally making it load indefinitely on an error. 😢

Not completely sure what you mean here, but it doesn't load indefinitely, it just shows a placeholder instead of the image. When it has an error it stops loading.

In my case. I have an jwt protected route that needs a valid auth header. Your plugin does not give control on when to flush CacheManager? Because my luck means that once I am renewing the user's token, your plugin wants to re-download the image resulting in a 401:

flutter: CacheManager: Failed to download file from https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png with error:

HttpException: Invalid statusCode: 401, uri = https://redacted/download?fileName=WnlCcuwy2_6ImgIZ73234lLsXs6M.png

Which means I need to change my list from a Stream to a Future or else this error will constantly pop up 😿

Can we not just do a silent retry? And after a certain amount of attempts can then throw the error, just in case that the internet had a bit of an issue or the server was a bit busy....

Here I also not fully sure what the problem is. Is it that you don't really get the exception in the app because it can still load the cached version? What exactly did you change from a Stream to a Future? You can always provide headers so it can download the file if needed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter_cached_network_image/issues/336#issuecomment-957223665, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIV7HB45EZ7ODC5ZAKIYKYLUJ6PVPANCNFSM4KT2WEOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

renefloor commented 2 years ago

@TylerByte666 I also have plans to add a retry mechanism. Would that be enough? Can the retry keep using the same headers, or should it request new headers?

TylerByte666 commented 2 years ago

That should be perfect, bro! 100%. Headers should be changeable if that's possible, I'm sure others need to send new tokens with the request too just incase the needed to refresh 😉

I love you guys and thank you so much for all the hardwork 💜

On Thu, 04 Nov 2021, 20:56 Rene Floor, @.***> wrote:

@TylerByte666 https://github.com/TylerByte666 I also have plans to add a retry mechanism. Would that be enough? Can the retry keep using the same headers, or should it request new headers?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter_cached_network_image/issues/336#issuecomment-961328962, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIV7HB2FXA5QKF67CN62O4TUKLJMZANCNFSM4KT2WEOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

dgurudot commented 2 years ago

We have been getting images from a repository and sometimes some images doesn't exist. We show a default image in those cases. We don't want our console logs to be cluttered with so much noise about the same error over and over again.

There are so many folks complaining about it so I am not sure why nobody from maintainers is looking to understand it. We can handle exceptions, errors and print whatever we want but this is a very valid scenario and let us handle it based on our use case.

I noticed earlier issues were also closed without resolution https://github.com/Baseflow/flutter_cached_network_image/issues/273

ronniechew commented 2 years ago

We have been getting images from a repository and sometimes some images doesn't exist. We show a default image in those cases. We don't want our console logs to be cluttered with so much noise about the same error over and over again.

There are so many folks complaining about it so I am not sure why nobody from maintainers is looking to understand it. We can handle exceptions, errors and print whatever we want but this is a very valid scenario and let us handle it based on our use case.

I noticed earlier issues were also closed without resolution #273

Exactly same issue here. The problem isn't being network issue or image temporary not available. Sometimes the image URL simply expired or entered wrongly for some reason.

In that scenario, I'd expect the plugin to render errorWidget and silent the error.

Imagine you have a list of 10+ invalid image links, every time you hot-reload this list you need to click 10+ times continue on the debugger to do debugging...

IMHO the plugin should gracefully handle invalid image URL error if errorWidget is provided, otherwise throw error as it is.

Thanks for the great plugin though :)

harithwick commented 2 years ago

Same issue here. the app seems to be crashing in production due to cached_network_image. Im playing around with https://pub.dev/packages/optimized_cached_image/ lets see how that goes

Giuliopretis commented 2 years ago

The issue still remains, and the odd thing is that happens only on certain devices.

zbahadir commented 2 years ago

I think most problems seem to be with non-english file naming. I've never had a problem with image files named only in English.

Is there any solution about this?

vigdora commented 2 years ago

the app is probably crashing in production for me as well for the same reason - I am getting this report in Crashlytics (FATAL) for multiple users now

image

is there a way to walk around it i.e - like adding some sort of try & catch (I tried Try/catch but obviously it didn't work for me)

ronniechew commented 2 years ago

the app is probably crashing in production for me as well for the same reason - I am getting this report in Crashlytics (FATAL) for multiple users now image is there a way to walk around it i.e - like adding some sort of try & catch (I tried Try/catch but obviously it didn't work for me)

Yes this is getting annoying... Even try catch wouldn't suspend the error.

Is there anyone able to help look into this please?

ken-ng-esotec commented 2 years ago

I also experienced this issue, and could not find a flutter way to solve the 404 issue which crashes the app.

As a solution, I am using imagekit as a CDN and we can tell imagekit to display a default image if the original image is missing: https://docs.imagekit.io/features/default-images

hasanmhallak commented 2 years ago

Thanks for this great plugin.

But why the console is cluttered with all that exceptions even if I provided an error builder? I have a list of users with like 20+ image and this is very annoying.

vigdora commented 2 years ago

I managed to reproduce the error locally - and I have a more descriptive logs from crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HttpException: Invalid statusCode: 403, uri = https://hiding-the-real-url loading image. Error thrown Non-Fatal error occured [Unhandled Error]. at CachedNetworkImage._octoErrorBuilder(cached_image_widget.dart:319) at ImageHandler._errorBuilder(image_handler.dart:299) at _ImageState.build(image.dart:1266) at StatefulElement.build(framework.dart:4870) at ComponentElement.performRebuild(framework.dart:4754) at StatefulElement.performRebuild(framework.dart:4928) at Element.rebuild(framework.dart:4477) at BuildOwner.buildScope(framework.dart:2659) at WidgetsBinding.drawFrame(binding.dart:882) at RendererBinding._handlePersistentFrameCallback(binding.dart:363) at SchedulerBinding._invokeFrameCallback(binding.dart:1144) at SchedulerBinding.handleDrawFrame(binding.dart:1081) at SchedulerBinding._handleDrawFrame(binding.dart:995)

can anyone from the contributors look at this?

saharvx9 commented 2 years ago

I managed to reproduce the error locally - and I have a more descriptive logs from crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HttpException: Invalid statusCode: 403, uri = https://hiding-the-real-url loading image. Error thrown Non-Fatal error occured [Unhandled Error]. at CachedNetworkImage._octoErrorBuilder(cached_image_widget.dart:319) at ImageHandler._errorBuilder(image_handler.dart:299) at _ImageState.build(image.dart:1266) at StatefulElement.build(framework.dart:4870) at ComponentElement.performRebuild(framework.dart:4754) at StatefulElement.performRebuild(framework.dart:4928) at Element.rebuild(framework.dart:4477) at BuildOwner.buildScope(framework.dart:2659) at WidgetsBinding.drawFrame(binding.dart:882) at RendererBinding._handlePersistentFrameCallback(binding.dart:363) at SchedulerBinding._invokeFrameCallback(binding.dart:1144) at SchedulerBinding.handleDrawFrame(binding.dart:1081) at SchedulerBinding._handleDrawFrame(binding.dart:995)

can anyone from the contributors look at this?

It happens to me yesterday too plss fix itt

vigdora commented 2 years ago

will someone take a look at this?

lnwfern13 commented 2 years ago

add comment file web_help.dart in flutter_cache_manager 3.3.0

// if (!hasNewFile && !keepOldFile) { // throw HttpExceptionWithStatus( // response.statusCode, // 'Invalid statusCode: ${response.statusCode}', // uri: Uri.parse(cacheObject.url), // ); // }

and chang file _image_loader.dart in cached_network_image 3.2.1

catch (exception, stack) { // Depending on where the exception was thrown, the image cache may not // have had a chance to track the key in the cache at all. // Schedule a microtask to give the cache a chance to add the key. scheduleMicrotask(() { evictImage(); }); chunkEvents.addError(exception, stack); //rethrow; }

dcg123 commented 2 years ago

在flutter_cache_manager 3.3.0 中添加注释文件web_help.dart

// if (!hasNewFile && !keepOldFile) {

// throw HttpExceptionWithStatus( // response.statusCode, // 'Invalid statusCode: ${response.statusCode}', // uri: Uri.parse(cacheObject.url), / /); // }

并在 cached_network_image 3.2.1 中更改文件 _image_loader.dart

catch (exception, stack) {

// 根据抛出异常的位置,图像缓存可能根本没有 机会跟踪缓存中的键。 // 调度一个微任务,让缓存有机会添加密钥。 scheduleMicrotask(() { evictImage(); }); chunkEvents.addError(异常,堆栈); //重新抛出; }

Thank you very much, it solved my problem, thumbs u

amitBlueVine commented 2 years ago

This is a really good package, I would hate to switch to a different one. Can someone from the contributors please have a look?

dgurudot commented 1 year ago

This is a constant complaint for long time and I am not sure if this message is reaching authors.

Can anyone want to consider forking or submit a pull request with fix ? Should be simple since it is just some error messages printing.

On May 18, 2022, at 2:02 PM, Hasan M. Hallak @.***> wrote:

 Thanks for this great plugin.

But why the console are cluttered with all that exceptions even if I provided an error builder? I have a list of user with like 20+ image and this is very annoying.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

felix-larsen commented 1 year ago

For crashlytics as a workaround you can filter for this Error before actually sending it to crashlytics like this:

FlutterError.onError = (flutterErrorDetails) async {
    if (flutterErrorDetails.library == "image resource service" &&
        flutterErrorDetails.exception
            .toString()
            .startsWith("HttpException: Invalid statusCode: 404, uri")) {
      return;
    }
    await FirebaseCrashlytics.instance
        .recordFlutterFatalError(flutterErrorDetails);
    return;
};
Amshaf123 commented 1 year ago

PS C:\Users\User\Desktop\OKD\okd> flutter run Launching lib\main.dart on CPH2387 in debug mode... ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:1: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name. Try adding the name of the type of the variable or the keyword 'var'. cimport 'dart:async'; ^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:1: Error: Expected ';' after this. cimport 'dart:async'; ^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:9: Error: Expected a declaration, but got ''dart:async''. cimport 'dart:async'; ^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:21: Error: Unexpected token ';'. cimport 'dart:async'; ^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:2:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'dart:typed_data'; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:3:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'dart:ui' as ui; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:4:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'dart:ui'; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:6:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart'; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:7:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'package:flutter/material.dart'; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:8:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'package:flutter_cache_manager/flutter_cache_manager.dart'; ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:10:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'package:cached_network_image_platform_interface' ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:13:1: Error: Directives must appear before any declarations. Try moving the directive before any declarations. import 'package:cached_network_image_platform_interface' ^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:24:5: Error: Type 'StreamController' not found. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:53:7: Error: Type 'StreamController' not found. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:83:5: Error: Type 'StreamController' not found. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:24:5: Error: 'StreamController' isn't a type. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:53:7: Error: 'StreamController' isn't a type. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:83:5: Error: 'StreamController' isn't a type. StreamController chunkEvents, ^^^^^^^^^^^^^^^^ ../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:129:7: Error: The method 'scheduleMicrotask' isn't defined for the class 'ImageLoader'.

FAILURE: Build failed with an exception.

BUILD FAILED in 17s how to solve this error

EarningsCall commented 10 months ago

For crashlytics as a workaround you can filter for this Error before actually sending it to crashlytics like this:

FlutterError.onError = (flutterErrorDetails) async {
    if (flutterErrorDetails.library == "image resource service" &&
        flutterErrorDetails.exception
            .toString()
            .startsWith("HttpException: Invalid statusCode: 404, uri")) {
      return;
    }
    await FirebaseCrashlytics.instance
        .recordFlutterFatalError(flutterErrorDetails);
    return;
};

I believe this works for solving firebase crashes, but there is another problem:

If you have a given URL, say example.com/image-123.png

and server returns 404, then the cache library will try to load that image over and over again, even if same response is always HTTP 404.

According to HTTP specifications, 4XX errors means some sort of client error, and therefore the problem is the request, not the server. You shouldn't retry the same request for 4XX errors because I'd expect the same response each time. Therefore, the cache library should store the result (HTTP 404) and return that instead.

EarningsCall commented 10 months ago

has anyone in the community found an alternative library that properly caches HTTP 4XX results?

ggirotto commented 10 months ago

It's so sad that the maintainers doesn't consider this as an issue

ridwanulhoquejr commented 5 months ago

It's been 4 years, but they still don't acknowledge this as an issue!!!