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

How to configure Sentry not to suppress the errors it sees #543

Closed
zambetpentru opened this issue Aug 9, 2021 · 15 comments
Closed

How to configure Sentry not to suppress the errors it sees #543

zambetpentru opened this issue Aug 9, 2021 · 15 comments
Assignees
Milestone

Comments

@zambetpentru
Copy link

Hi,

I am starting with Flutter Sentry for Web and it is working but when an error occurs it suppresses the error from being shown on the console. Is there a way to log the error but all it to throw an exception as it would normally do?

Warm regards,
Zambet

@ueman
Copy link
Collaborator

ueman commented Aug 9, 2021

Thanks for raising the issue.

This is already fixed in #533

I think it's already in the latest beta but it will be available in the next version.

@ueman ueman closed this as completed Aug 9, 2021
@zambetpentru
Copy link
Author

zambetpentru commented Aug 9, 2021

Great thanks for your reply, I see that ticket says to always fire the error - is there a way to make it optional as I think that's a useful feature for Flutter Web to have it configurable to be able to hide it from the dev console.

@zambetpentru
Copy link
Author

Hi @ueman, I am using Beta 3 which appears to have the change in it but I can still see it suppress the console errors in Flutter Web. Can you confirm?

@ueman
Copy link
Collaborator

ueman commented Aug 11, 2021

Error are shown in the debug console (e.g. VS Code or IntelliJ). As far as I know they aren't shown in the browser which is the connected device. You probably should create an issue on the Flutter repo if you want that behavior.

@zambetpentru
Copy link
Author

Somethings a picture just helps :-)

Without Sentry I get this when I run the test application from Sentry_Flutter:

image

When using 6.0.0-beta.3 I do not get anything in the Console of the browser (so there's no way to know an error occurred without watching for the envelope API requests or checking sentry.io).

image

The request is to have both :-)

@ueman ueman reopened this Aug 11, 2021
@ueman
Copy link
Collaborator

ueman commented Aug 11, 2021

Ah I see, yeah that looks like an bug. We'll check it out.

@ueman ueman added flutter flutter bug labels Aug 17, 2021
@hitokiri82
Copy link

+1 on this. Any updates on when this will be fixed?

@marandaneto
Copy link
Contributor

Ah I see, yeah that looks like an bug. We'll check it out.

@ueman have you checked this out? I don't remember the outcome of this issue.

@ueman
Copy link
Collaborator

ueman commented Nov 17, 2022

This doesn't seem to be fixed, since the overridden onError doesn't call presentError, as seen in:

void call(Hub hub, SentryFlutterOptions options) {
_defaultOnError = FlutterError.onError;
_integrationOnError = (FlutterErrorDetails errorDetails) async {
final exception = errorDetails.exception;
options.logger(
SentryLevel.debug,
'Capture from onError $exception',
);
if (errorDetails.silent != true || options.reportSilentFlutterErrors) {
final context = errorDetails.context?.toDescription();
final collector = errorDetails.informationCollector?.call() ?? [];
final information =
(StringBuffer()..writeAll(collector, '\n')).toString();
// errorDetails.library defaults to 'Flutter framework' even though it
// is nullable. We do null checks anyway, just to be sure.
final library = errorDetails.library;
final flutterErrorDetails = <String, String>{
// This is a message which should make sense if written after the
// word `thrown`:
// https://api.flutter.dev/flutter/foundation/FlutterErrorDetails/context.html
if (context != null) 'context': 'thrown $context',
if (collector.isNotEmpty) 'information': information,
if (library != null) 'library': library,
};
options.logger(
SentryLevel.error,
errorDetails.toStringShort(),
logger: 'sentry.flutterError',
exception: exception,
stackTrace: errorDetails.stack,
);
// FlutterError doesn't crash the App.
final mechanism = Mechanism(
type: 'FlutterError',
handled: true,
data: {
if (flutterErrorDetails.isNotEmpty)
'hint':
'See "flutter_error_details" down below for more information'
},
);
final throwableMechanism = ThrowableMechanism(mechanism, exception);
var event = SentryEvent(
throwable: throwableMechanism,
level: SentryLevel.fatal,
contexts: flutterErrorDetails.isNotEmpty
? (Contexts()..['flutter_error_details'] = flutterErrorDetails)
: null,
// ignore: invalid_use_of_internal_member
timestamp: options.clock(),
);
await hub.captureEvent(event, stackTrace: errorDetails.stack);
// we don't call Zone.current.handleUncaughtError because we'd like
// to set a specific mechanism for FlutterError.onError.
} else {
options.logger(
SentryLevel.debug,
'Error not captured due to [FlutterErrorDetails.silent], '
'Enable [SentryFlutterOptions.reportSilentFlutterErrors] '
'if you wish to capture silent errors',
);
}
// Call original handler, regardless of `errorDetails.silent` or
// `reportSilentFlutterErrors`. This ensures, that we don't swallow
// messages.
if (_defaultOnError != null) {
_defaultOnError!(errorDetails);
}
};

The default implementation for onError does it, though: static FlutterExceptionHandler? onError = presentError;

See

I think there were problems with the debugPrint breadcrumbs because presentError would call debugPrint. I think those were resolved, but it should be checked again.

@marandaneto
Copy link
Contributor

@ueman fair point but we always forward the call to the default handler

if (_defaultOnError != null) {
_defaultOnError!(errorDetails);
}

@marandaneto
Copy link
Contributor

So the problem here is not the FlutterErrorIntegration but rather the RunZonedGuardedIntegration which is responsible for capturing the errors shown in the issue description.
We do log the error tho,

options.logger(
SentryLevel.error,
'Uncaught zone error',
logger: 'sentry.runZonedGuarded',
exception: exception,
stackTrace: stackTrace,
);

But options.debug should be enabled.
@ueman if there's no runZonedGuarded at all, Flutter only prints out to the console I believe? Maybe in this case, we should do something similar to presentError, which is calling debugPrint or debugPrintStack, so at least is shown?

@marandaneto marandaneto added this to the 7.0.0 milestone Dec 12, 2022
@ueman
Copy link
Collaborator

ueman commented Dec 12, 2022

That's a good question and I'm not really sure. I would believe, that without the runZoneGuarded the default behavior is used, because Sentry doesn't mess with it. Or does Sentry do something that intercepts it somehow?

@marandaneto
Copy link
Contributor

Nope, we don't do anything, but I believe Flutter itself does something in case there's no runZoneGuarded at all, which is likely printing out to the console, we always forward to the default handler, but in case of runZoneGuarded, and Isolate.current.addErrorListener, no default callbacks exist, so we don't do anything besides logging out to our debug logger.
For FlutterError.onError and PlatformDispatcher.onError, we do call the default handler.

@denrase denrase self-assigned this Jan 17, 2023
@denrase
Copy link
Collaborator

denrase commented Jan 17, 2023

Using debugPrint or debugPrintStack does not yield the same result in the (web) console as and error without sentry. Do we know which method/function to call to have the same formatting (red). like without sentry?

Bildschirm­foto 2023-01-17 um 13 32 39

@denrase
Copy link
Collaborator

denrase commented Jan 17, 2023

When calling handleUncaughtError it is rendered correctly. This is the same as the default in the platform dispatcher that @ueman linked to when we were discussing the handled flag.

https://github.com/flutter/engine/blob/74a9c7e0f9b16cf8e26b2d1ce7b7777ae2a07572/lib/ui/platform_dispatcher.dart#L1141-L1183

@marandaneto marandaneto moved this from Backlog to In Progress in Mobile & Cross Platform SDK Jan 17, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Mobile & Cross Platform SDK Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants