flutterfire
flutterfire copied to clipboard
🐛 [firebase_crashlytics] Handling exception in Image.network
Bug report
I'm using Image.network with errorBuilder but crashlytics is still filled with exceptions. Because of these exceptions, I'm unable to see real issues in the firebase dashboard, because thousands of exceptions are related to Image.network only. I would like not to get any of the Image.network exceptions, even if the image URL throws 404 or some other invalid status codes. Even if internet was not available at that time, it should not throw exception. I just want to show Image.asset if an image was not found on Image.network.
Steps to reproduce
Image.network(
"https://example.com/404.png",
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/noImage.png");
},
)
Expected behaviour
Crashlytics should not pick up exception because we are already handling it with "errorBuilder"
@sukhcha-in
Can you provide flutter doctor -v, plugin version and the exceptions you are receiving in crashlytics ?
@darshankawar
Firebase console:
These exceptions should not be caught by Crashlytics, because I already have an errorBuilder, If some exception is raised it should just show an asset image inside errorBuilder
Some examples:
Connection error while the internet was not available or something like that:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HandshakeException: Connection terminated during handshake. Error thrown Instance of 'ErrorDescription'.
404 Image not found, Why throw an error?
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HttpException: Invalid statusCode: 404, uri = https://example.com/404.png. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Connection closed before full header was received. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Connection closed while receiving data. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Connection reset by peer. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Software caused connection abort. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: SocketException: Failed host lookup: 'cdn.example.com' (OS Error: No address associated with hostname, errno = 7). Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = cdn.example.com, port = 443. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Connection timed out. Error thrown Instance of 'ErrorDescription'.
Another one:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate chain(handshake.cc:393)). Error thrown Instance of 'ErrorDescription'.
Flutter doctor output:
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.3.1 21E258 darwin-arm, locale en-IN)
• Flutter version 3.0.1 at /Users/sukh/Developer/Flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision fb57da5f94 (7 weeks ago), 2022-05-19 15:50:29 -0700
• Engine revision caaafc5604
• Dart version 2.17.1
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/sukh/Library/Android/sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.68.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (3 available)
• SM G950F (mobile) • ce12171c394a541d05 • android-arm64 • Android 9 (API 28)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.3.1 21E258 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Thanks for the update. I see same behavior using code sample provided and logs from crashlytics. Keeping it open and labeling for further insights from the team.
Same here as well. We cannot tell any back-end guys to update image and all because we are already handling these in error builder and we do not want that in our firebase crashlogs
face same issue here
Same here , we should not report error on firebase crashlytics if we are already handling them through image view
/cc @russellwheatley
We are still facing this issue, waiting for update.
Are you sure the error isn't coming from inside the errorBuilder? I've just tested this and it does not log the error if you actually have an asset. For illustration:
If you have this setup:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FlutterError.onError = (errorDetails) {
// ERROR HANDLER THAT SENDS UNCAUGHT ERRORS TO CRASHLYTICS
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
runApp(MyApp());
The exception will make its way to the error handler if your asset does not exist:
Image.network(
"https://example.com/404.png",
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
// THIS WILL MAKE ITS WAY TO THE ERROR HANDLER IF IT DOES NOT EXIST
return Image.asset("assets/noImage.png");
},
)
If the asset exists, no error in the error handler.
Hey @sukhcha-in. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
@russellwheatley
I have recordFlutterError instead of recordFlutterFatalError just like documentation suggests.
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
It doesn't matter which one you use, it has to reach FlutterError.onError for either recordFlutterError or recordFlutterFatalError to be called.
@russellwheatley Okay! I think there is no reason to close this issue, Console is full of image errors even when using errorBuilder.
Did you read this?
Please provide a reproduction as I can't reproduce. Preferably a github repo. Thanks.
@russellwheatley I have the exact code mentioned in this snippet.
Hey @sukhcha-in. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@sukhcha-in if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
if you're still experiencing this problem
Yes
Reopening based on above comment and for further action.
/cc @russellwheatley
I have the same issue with network images but using the CachedNetworkImage See https://github.com/flutter/flutter/issues/102494
I'm closing this out as I have already requested a reproduction which the OP has not provided. If you're seeing exceptions it is highly likely that your asset does not exist or you have not specified it in your pubspec.yaml as I have already explained here.