Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sentry_flutter] Sentry will automatically uploads 'Flutter Error', Uncontrolled #216

Closed
chvin opened this issue Dec 3, 2020 · 1 comment

Comments

@chvin
Copy link

chvin commented Dec 3, 2020

On sentry_flutter: ^4.0.0-alpha.2

After initialize sentry, sentry will automatically uploads 'Flutter Error', Uncontrolled. Full code:

// main.dart
import 'dart:async';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:flutter/material.dart';

void main() {
  // release: true, debug|profile: false
  // As suggested by: https://twitter.com/FlutterDev/status/1048278525432791041
  const bool isProduction = const bool.fromEnvironment('dart.vm.product');

  // handle Flutter error
  FlutterError.onError = (FlutterErrorDetails details,) async {
    if (!isProduction) {
      FlutterError.dumpErrorToConsole(details);
      return;
    }
    // turn to Zone
    Zone.current.handleUncaughtError(details.exception, details.stack);
  };

  // Handle dart error
  runZonedGuarded<Future<void>>(() async {
    SentryFlutter.init((options) => options.dsn = 'xxx',
      () {
        runApp(MyApp());
      },
    );
  }, (Object error,  StackTrace stackTrace) async {
    if (!isProduction) {
      print(error);
      print(stackTrace);
      return;
    }
    // Only upload error on release mode
    Sentry.captureException(
      error,
      stackTrace: stackTrace,
    );
  });
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Exception Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
      backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text('Error test'),
        ),
        // https://flutter.dev/docs/testing/common-errors#a-renderflex-overflowed
        body: Row(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("Title", style: Theme.of(context).textTheme.headline4),
                Text(
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed"
                " do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud "
                "exercitation ullamco laboris nisi ut aliquip ex ea "
                "commodo consequat."),
              ],
            ),
          ],
        )
      )
    );
  }
}

The above code triggered a Flutter error(layout error).
In debug mode running, Sentry still upload error.

@marandaneto
Copy link
Contributor

@chvin that's true, you have 2 options, either you don't init. Sentry on debug mode or you can use the beforeSend hook to filter the events which are on a debug environment.

For example:
https://docs.sentry.io/platforms/flutter/data-management/sensitive-data/#scrubbing-data

if an event has the environment field set debug, just return null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants