Unverified Commit 08ca8b01 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix error resolution when a completer is already set (#81014)

parent 7b0c8267
......@@ -333,8 +333,6 @@ abstract class ImageProvider<T extends Object> {
},
(T? key, Object exception, StackTrace? stack) async {
await null; // wait an event turn in case a listener has been added to the image stream.
final _ErrorImageCompleter imageCompleter = _ErrorImageCompleter();
stream.setCompleter(imageCompleter);
InformationCollector? collector;
assert(() {
collector = () sync* {
......@@ -344,7 +342,10 @@ abstract class ImageProvider<T extends Object> {
};
return true;
}());
imageCompleter.setError(
if (stream.completer == null) {
stream.setCompleter(_ErrorImageCompleter());
}
stream.completer!.reportError(
exception: exception,
stack: stack,
context: ErrorDescription('while resolving an image'),
......@@ -1127,25 +1128,7 @@ class ExactAssetImage extends AssetBundleImageProvider {
}
// A completer used when resolving an image fails sync.
class _ErrorImageCompleter extends ImageStreamCompleter {
_ErrorImageCompleter();
void setError({
DiagnosticsNode? context,
required Object exception,
StackTrace? stack,
InformationCollector? informationCollector,
bool silent = false,
}) {
reportError(
context: context,
exception: exception,
stack: stack,
informationCollector: informationCollector,
silent: silent,
);
}
}
class _ErrorImageCompleter extends ImageStreamCompleter {}
/// The exception thrown when the HTTP request to load a network image fails.
class NetworkImageLoadException implements Exception {
......
......@@ -668,7 +668,6 @@ abstract class ImageStreamCompleter with Diagnosticable {
/// messages, but errors during development will still be reported.
///
/// See [FlutterErrorDetails] for further details on these values.
@protected
@pragma('vm:notify-debugger-on-exception')
void reportError({
DiagnosticsNode? context,
......
......@@ -90,7 +90,9 @@ void main() {
await testZone.run(() async {
final ImageProvider imageProvider = LoadErrorCompleterImageProvider();
final Completer<bool> caughtError = Completer<bool>();
final Completer<bool> onErrorCompleter = Completer<bool>();
FlutterError.onError = (FlutterErrorDetails details) {
onErrorCompleter.complete(true);
throw Error();
};
final ImageStream result = imageProvider.resolve(ImageConfiguration.empty);
......@@ -99,6 +101,7 @@ void main() {
caughtError.complete(true);
}));
expect(await caughtError.future, true);
expect(await onErrorCompleter.future, true);
});
expect(uncaught, false);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment