Repository navigation
Failure of ImageProvider's error handling #44579
Description
@escamoteur and I have been working on an app and a bug in our revealed a whole set of issues within the framework for handling image errors. A bug in our app tried to load a Image file with zero-byte file size which causes the follow chain of events to occur.
Chain of events
ImageProvider.resolvesets up a uncaught exception handler and callsobtainKeyandloadonFileImageto load the image codec. The way it handles errors here seems very complicated for what is actually required.FileImage.loadis called and creates aMultiFrameImageStreamCompleterand returns it with the codec loading asynchronously.FileImage._loadAsynclater returns anullwhen it detects the 0 length file.MultiFrameImageStreamCompleterconstructor had setup an error handler for codec loading failures; however becausenullis reported as a successful response the value is passed toMultiFrameImageStreamCompleter._handleCodecReadywhich asserts that it can't be null. Because this function does not return aFuturethe assertion is passed down and caught by our uncaught exception handler rather than by the actual codec failure handler. Secondly this codec failure handler gobbles the error and does not pass it down to theImageStream?- The uncaught exception is passed over to be handled by
ImageProvider.resolve.handleErrorwhich then further attempts to set the completer on theImageStreamto its own to error completer which further causes an assertion because aImageStreams completer can only be set once, and it was previously successfully set by the synchronousloadcallback;
Thoughts
There are several failures in this chain.. all of which should never have occurred. I am happy to address these as bugs, but to be honest it seems as though a rethink of how ImageProvider errors are handled is probably in order.
It should also be possible to handle these errors gracefully and not silently from within the Image widget. I think we've needed a errorBuilder on it for a long time, and since we now have an error listener as part of ImageCompleter it should be accessible to the end developer.
Steps to Reproduce
Run the example code below in Debug mode of your IDE.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart' as pp;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final tmp = await pp.getTemporaryDirectory();
final blank = await File(p.join(tmp.path, 'test.jpg')).create(recursive: true);
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Center(
child: Image.file(blank),
),
),
),
);
}Logs
[√] Flutter (Channel dev, v1.10.15, on Microsoft Windows [Version 10.0.17763.805], locale en-GB)
• Flutter version 1.10.15 at C:\Android\flutter
• Framework revision fbabb264e0 (10 days ago), 2019-11-02 01:36:07 +0300
• Engine revision 8ea19b1c76
• Dart version 2.6.0 (build 2.6.0-dev.8.2 bbe2ac28c9)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Android\SDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = C:\Android\SDK
• Java binary at: C:\Android\Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 3.5)
• Android Studio at C:\Android\Studio
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] IntelliJ IDEA Ultimate Edition (version 2019.2)
• IntelliJ at C:\Users\Simon\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6817.14
• Flutter plugin version 39.0.4
• Dart plugin version 192.6527
[√] VS Code, 64-bit edition (version 1.27.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 2.18.0
[√] Connected device (3 available)
• iPhone • 192.168.188.108:5555 • android-x86 • Android 8.0.0 (API 26)
• Chrome • chrome • web-javascript • Google Chrome 78.0.3904.87
• Web Server • web-server • web-javascript • Flutter Tools
• No issues found!
Activity
JamesMcIntosh commentedon Dec 2, 2019
Hi @slightfoot, in point 4 you talk about the assert, in production it will continue over this assert which results in the following error.
kw2019ltd commentedon Jan 26, 2020
same issue multiple times
Non-fatal Exception: java.lang.Exception: NoSuchMethodError: The method 'getNextFrame' was called on null.
Receiver: null
Tried calling: getNextFrame()
at MultiFrameImageStreamCompleter._decodeNextFrameAndSchedule(image_stream.dart:680)
at MultiFrameImageStreamCompleter._handleCodecReady(image_stream.dart:644)
at FileImage._loadAsync(image_provider.dart)
at FileImage.load(image_provider.dart:638)
at ImageProvider.resolve...(image_provider.dart:327)
at ImageCache.putIfAbsent(image_cache.dart:160)
at ImageProvider.resolve..(image_provider.dart:325)
at SynchronousFuture.then(synchronous_future.dart:38)
at ImageProvider.resolve.(image_provider.dart:323)
at ImageProvider.resolve(image_provider.dart:315)
at _ImageState._resolveImage(image.dart:1010)
at _ImageState.didChangeDependencies(image.dart:967)
at StatefulElement._firstBuild(framework.dart:4376)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at ParentDataElement.mount(framework.dart:4617)
at Element.inflateWidget(framework.dart:3194)
at MultiChildRenderObjectElement.mount(framework.dart:5551)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at MultiChildRenderObjectElement.mount(framework.dart:5551)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at MultiChildRenderObjectElement.mount(framework.dart:5551)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at MultiChildRenderObjectElement.mount(framework.dart:5551)
at _ViewportElement.mount(viewport.dart:186)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at SingleChildRenderObjectElement.mount(framework.dart:5445)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at StatefulElement._firstBuild(framework.dart:4381)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at ComponentElement.performRebuild(framework.dart:4243)
at Element.rebuild(framework.dart:3947)
at ComponentElement._firstBuild(framework.dart:4206)
at ComponentElement.mount(framework.dart:4201)
at Element.inflateWidget(framework.dart:3194)
at Element.updateChild(framework.dart:2988)
at _LayoutBuilderElement._layout.(layout_builder.dart:115)
at BuildOwner.buildScope(framework.dart:2412)
at _LayoutBuilderElement._layout(layout_builder.dart:95)
at RenderObject.invokeLayoutCallback.(object.dart:1823)
at PipelineOwner._enableMutationsToDirtySubtrees(object.dart:875)
at RenderObject.invokeLayoutCallback(object.dart:1823)
at RenderConstrainedLayoutBuilder.layoutAndBuildChild(layout_builder.dart:173)
at _RenderLayoutBuilder.performLayout(layout_builder.dart:240)
at RenderObject.layout(object.dart:1724)
at RenderProxyBoxMixin.performLayout(proxy_box.dart:105)
at RenderObject.layout(object.dart:1724)
at MultiChildLayoutDelegate.layoutChild(custom_layout.dart:163)
at _ScaffoldLayout.performLayout(scaffold.dart:477)
at MultiChildLayoutDelegate._callPerformLayout(custom_layout.dart:232)
at RenderCustomMultiChildLayoutBox.performLayout(custom_layout.dart:391)
at RenderObject._layoutWithoutResize(object.dart:1584)
at PipelineOwner.flushLayout(object.dart:844)
at RendererBinding.drawFrame(binding.dart:344)
at WidgetsBinding.drawFrame(binding.dart:774)
at RendererBinding._handlePersistentFrameCallback(binding.dart:283)
at SchedulerBinding._invokeFrameCallback(binding.dart:1102)
at SchedulerBinding.handleDrawFrame(binding.dart:1041)
at SchedulerBinding._handleDrawFrame(binding.dart:957)
dnfield commentedon Feb 7, 2020
I believe the fix for this is to just throw if the file is zero length rather than returning null. That should trigger the expected error handling to kick in. Am I missing something?
dnfield commentedon Feb 7, 2020
Ah - I fixed part of this in #50242 - unintentionally. But the rest of the fix is to throw instead of returning null.
escamoteur commentedon Mar 12, 2020
@dnfield I don't think just throwing is the solution because the Exception is swallowed by the 'Image' so it can't be handled on the WidgetTree level see #19993.
The right way would be to have an ErrorBuilder in Image that received the exception.
dnfield commentedon Mar 12, 2020
Ahhh.
We should probably add onError to
flutter/packages/flutter/lib/src/widgets/image.dart
Line 1020 in 0b8abb4
dnfield commentedon Mar 12, 2020
And in all fairness, the bug was opened against ImageProvider, not the Image widget. The errorBuilder is a perfectly reasonable request, but I hope it's understandable why I closed it for the ImageProvider related fixes.
escamoteur commentedon Mar 19, 2020
@dnfield What is strange, that if I select 'break on uncaught exceptions' in VS code, the debugger breaks on Image errors before it calls the new errorBuilder.
dnfield commentedon Mar 19, 2020
It probably has something to do with the way the zones are set up and where the error handling occurs. The errors can get thrown in a lot of different ways (sync, async, into the zone wrapping image loading, into the zone above it). This is a real exception though, and if nothing else it's getting handled by the zone handler that propagates it back to error builder.
escamoteur commentedon Mar 19, 2020
Yeah but the error builder catches it or not?
dnfield commentedon Mar 19, 2020
Image decoding is run in a separate zone - there's a zone error handler set up in image_cache.dart that's catching it. But it's catching it in a way the debugger probably doesn't handle (it's not a regular try..catch block, it's a zone error handler).
escamoteur commentedon Mar 19, 2020
So we can't do anything tere?
dnfield commentedon Mar 19, 2020
I'm not clear on what the issue is - if you're concerned about breaking on uncaught exceptions and don't want to break here, then you should fix your code up locally so it doesn't throw an exception (e.g. make sure the image is available and valid).
If you're concerned that this isn't getting propagated to the error handler, please share a test case and we can try to fix it.
If it's something else entirely, I'm just missing it and could use some help :)
escamoteur commentedon Mar 20, 2020
Ok, the first one :-) in that case I would have to call a File.Exists before which isn't ideal either but I get your point
lock commentedon Apr 4, 2020
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.