Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export 'src/sentry_baggage.dart';
export 'src/exception_cause_extractor.dart';
export 'src/exception_cause.dart';
export 'src/exception_stacktrace_extractor.dart';
export 'src/error_type_identifier.dart';
// URL
// ignore: invalid_export_of_internal_element
export 'src/utils/http_sanitizer.dart';
Expand Down
19 changes: 19 additions & 0 deletions dart/lib/src/dart_error_type_identifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '../sentry.dart';

class DartErrorIdentifier implements ErrorTypeIdentifier {
@override
String? getTypeName(dynamic error) {
if (error is NoSuchMethodError) return 'NoSuchMethodError';
if (error is FormatException) return 'FormatException';
if (error is TypeError) return 'TypeError';
if (error is ArgumentError) return 'ArgumentError';
if (error is StateError) return 'StateError';
if (error is UnsupportedError) return 'UnsupportedError';
if (error is UnimplementedError) return 'UnimplementedError';
if (error is ConcurrentModificationError)
return 'ConcurrentModificationError';
if (error is OutOfMemoryError) return 'OutOfMemoryError';
if (error is StackOverflowError) return 'StackOverflowError';
return null;
}
}
3 changes: 3 additions & 0 deletions dart/lib/src/error_type_identifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class ErrorTypeIdentifier {
String? getTypeName(dynamic error);
}
25 changes: 13 additions & 12 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import 'dart:async';
import 'dart:math';

import 'package:meta/meta.dart';
import 'utils/stacktrace_utils.dart';
import 'metrics/metric.dart';
import 'metrics/metrics_aggregator.dart';
import 'sentry_baggage.dart';
import 'sentry_attachment/sentry_attachment.dart';

import 'client_reports/client_report_recorder.dart';
import 'client_reports/discard_reason.dart';
import 'event_processor.dart';
import 'hint.dart';
import 'sentry_trace_context_header.dart';
import 'sentry_user_feedback.dart';
import 'transport/rate_limiter.dart';
import 'metrics/metric.dart';
import 'metrics/metrics_aggregator.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_attachment/sentry_attachment.dart';
import 'sentry_baggage.dart';
import 'sentry_envelope.dart';
import 'sentry_exception_factory.dart';
import 'sentry_options.dart';
import 'sentry_stack_trace_factory.dart';
import 'sentry_trace_context_header.dart';
import 'sentry_user_feedback.dart';
import 'transport/data_category.dart';
import 'transport/http_transport.dart';
import 'transport/noop_transport.dart';
import 'transport/rate_limiter.dart';
import 'transport/spotlight_http_transport.dart';
import 'transport/task_queue.dart';
import 'utils/isolate_utils.dart';
import 'utils/stacktrace_utils.dart';
import 'version.dart';
import 'sentry_envelope.dart';
import 'client_reports/client_report_recorder.dart';
import 'client_reports/discard_reason.dart';
import 'transport/data_category.dart';

/// Default value for [SentryUser.ipAddress]. It gets set when an event does not have
/// a user and IP address. Only applies if [SentryOptions.sendDefaultPii] is set
Expand Down
16 changes: 12 additions & 4 deletions dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'utils/stacktrace_utils.dart';

import 'recursive_exception_cause_extractor.dart';
import 'protocol.dart';
import 'recursive_exception_cause_extractor.dart';
import 'sentry_options.dart';
import 'sentry_stack_trace_factory.dart';
import 'throwable_mechanism.dart';
import 'utils/stacktrace_utils.dart';

/// class to convert Dart Error and exception to SentryException
class SentryExceptionFactory {
Expand Down Expand Up @@ -62,10 +61,19 @@ class SentryExceptionFactory {
final stackTraceString = stackTrace.toString();
final value = throwableString.replaceAll(stackTraceString, '').trim();

String errorTypeName = throwable.runtimeType.toString();
for (final errorTypeIdentifier in _options.errorTypeIdentifiers) {
final identifiedErrorType = errorTypeIdentifier.getTypeName(throwable);
if (identifiedErrorType != null) {
errorTypeName = identifiedErrorType;
break;
}
}

// if --obfuscate feature is enabled, 'type' won't be human readable.
// https://flutter.dev/docs/deployment/obfuscate#caveat
return SentryException(
type: (throwable.runtimeType).toString(),
type: errorTypeName,
value: value.isNotEmpty ? value : null,
mechanism: mechanism,
stackTrace: sentryStackTrace,
Expand Down
17 changes: 14 additions & 3 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'dart:async';
import 'dart:developer';

import 'package:meta/meta.dart';
import 'package:http/http.dart';
import 'package:meta/meta.dart';

import '../sentry.dart';
import 'client_reports/client_report_recorder.dart';
import 'client_reports/noop_client_report_recorder.dart';
import 'sentry_exception_factory.dart';
import 'sentry_stack_trace_factory.dart';
import 'dart_error_type_identifier.dart';
import 'diagnostic_logger.dart';
import 'environment/environment_variables.dart';
import 'noop_client.dart';
import 'sentry_exception_factory.dart';
import 'sentry_stack_trace_factory.dart';
import 'transport/noop_transport.dart';
import 'version.dart';

Expand Down Expand Up @@ -436,6 +437,16 @@ class SentryOptions {
/// Settings this to `false` will set the `level` to [SentryLevel.error].
bool markAutomaticallyCollectedErrorsAsFatal = true;

final List<ErrorTypeIdentifier> _errorTypeIdentifiers = [
DartErrorIdentifier(),
];

List<ErrorTypeIdentifier> get errorTypeIdentifiers => _errorTypeIdentifiers;

void addErrorTypeIdentifier(ErrorTypeIdentifier errorTypeIdentifier) {
_errorTypeIdentifiers.add(errorTypeIdentifier);
}

/// The Spotlight configuration.
/// Disabled by default.
/// ```dart
Expand Down
17 changes: 17 additions & 0 deletions flutter/lib/src/flutter_error_type_identifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

import '../sentry_flutter.dart';

class FlutterErrorIdentifier implements ErrorTypeIdentifier {
@override
String? getTypeName(dynamic error) {
if (error is FlutterError) return 'FlutterError';
if (error is PlatformException) return 'PlatformException';
if (error is MissingPluginException) return 'MissingPluginException';
if (error is AssertionError) return 'AssertionError';
if (error is NetworkImageLoadException) return 'NetworkImageLoadException';
if (error is TickerCanceled) return 'TickerCanceled';
return null;
}
}
15 changes: 8 additions & 7 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ import 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
import 'span_frame_metrics_collector.dart';

import '../sentry_flutter.dart';
import 'event_processor/android_platform_exception_event_processor.dart';
import 'event_processor/flutter_enricher_event_processor.dart';
import 'event_processor/flutter_exception_event_processor.dart';
import 'event_processor/platform_exception_event_processor.dart';
import 'event_processor/widget_event_processor.dart';
import 'file_system_transport.dart';
import 'flutter_error_type_identifier.dart';
import 'frame_callback_handler.dart';
import 'integrations/connectivity/connectivity_integration.dart';
import 'integrations/integrations.dart';
import 'integrations/screenshot_integration.dart';
import 'native/factory.dart';
import 'native/native_scope_observer.dart';
import 'native/sentry_native_binding.dart';
import 'profiling.dart';
import 'renderer/renderer.dart';

import 'integrations/integrations.dart';
import 'event_processor/flutter_enricher_event_processor.dart';

import 'file_system_transport.dart';

import 'span_frame_metrics_collector.dart';
import 'version.dart';
import 'view_hierarchy/view_hierarchy_integration.dart';

Expand Down Expand Up @@ -138,6 +137,8 @@ mixin SentryFlutter {

options.addPerformanceCollector(SpanFrameMetricsCollector(options));

options.addErrorTypeIdentifier(FlutterErrorIdentifier());

_setSdk(options);
}

Expand Down