sentry-dart icon indicating copy to clipboard operation
sentry-dart copied to clipboard

Not all errors are caught by Sentry on Flutter Web

Open daniel-v opened this issue 1 year ago • 3 comments

Platform

Flutter Web

Obfuscation

Disabled

Debug Info

Disabled

Doctor

Flutter doctor
  
[✓] Flutter (Channel stable, 3.19.1, on Fedora Linux 39 (KDE Plasma) 6.7.5-200.fc39.x86_64, locale en_US.UTF-8)
    • Flutter version 3.19.1 on channel stable at /home/dvh/Documents/ThirdParty/flutter-3.19
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision abb292a07e (6 days ago), 2024-02-20 14:35:05 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/dvh/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
    • pkg-config version 1.9.5
    ✗ GTK 3.0 development libraries are required for Linux development.
      They are likely available from your distribution (e.g.: apt install libgtk-3-dev)

[✓] Android Studio (version 2023.1)
    • Android Studio at /home/dvh/Documents/ThirdParty/android-studio
    • 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 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.86.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.82.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 39 (KDE Plasma) 6.7.5-200.fc39.x86_64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 122.0.6261.69

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Version

7.16.1

Steps to Reproduce

Follow the instructions of setting Sentry up on its

  1. package page OR
  2. documentation page OR
  3. the onboarding wizard of a new Sentry project

Expected Result

Callback errors such as the code sample below is caught by Sentry and reported.

 ElevatedButton(
  onPressed: () {
    throw StateError(
        'Sync callback errors are caught by FlutterError');
  },
  child: const Text('Sync callback error'),
)

Actual Result

Sentry does not capture the error and never reports it.

Are you willing to submit a PR?

Yes

daniel-v avatar Feb 26 '24 18:02 daniel-v

A bit of clarification that did not fit in the previous comment by format:

This is verified only on Flutter Web. Other platforms are not tested.

I am not sure as to WHY this is happening, only that I observed this kind of behavior. As per the Flutter documentation, Sentry does what it should at first blick.

I did, however find a relevant SDK issue: https://github.com/flutter/flutter/issues/129595

The easiest workaround I found was to also provide a FlutterError callback as seen here:

  var currentOnError = FlutterError.onError;
  FlutterError.onError = (details) {
    debugPrint('**** FlutterError.onError invoked for:');
    FlutterError.presentError(details);
    if (currentOnError != null) {
      currentOnError(details);
    }
  };

A quick win could be an update to docs, README and the onboarding wizard to let Flutter web users know about this?

daniel-v avatar Feb 26 '24 18:02 daniel-v

Thank you @daniel-v, highly appreciated!

kahest avatar Feb 27 '24 08:02 kahest

@daniel-v yeah documenting it sounds good, we have a flutter troubleshooting section at sentry-docs to which we can add the workaround

buenaflor avatar Mar 14 '24 12:03 buenaflor