-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Implement error type identifier to mitigate obfuscated Flutter issue titles #2170
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5e26214
try to mitigate runtime type not being obfuscated
buenaflor c3d307f
fix imports
buenaflor aa007d4
Remove prints
buenaflor 526102e
Update
buenaflor 745a18f
Update
buenaflor 34c4e11
Update exception_type_identifier.dart
buenaflor df9c16e
Add caching
buenaflor ff04d22
Update
buenaflor 4fb9c86
split up dart:io and dart:html exceptions
buenaflor 4aaa838
Merge branch 'main' into improvement/flutter-issues-title
buenaflor 04dace5
fix analyze
buenaflor 40fba24
Update CHANGELOG
buenaflor 51e25c0
update
buenaflor bc25f48
Add more tests
buenaflor fe9144f
Update docs
buenaflor c22636f
Update options docs
buenaflor f9da0a4
remove print
buenaflor 0305205
remove CustomException
buenaflor facc3ba
import with show
buenaflor c31fee1
try fix test
buenaflor 5eeeef9
Update CHANGELOG.md
buenaflor 7398345
Merge branch 'main' into improvement/flutter-issues-title
buenaflor cee56f3
Update CHANGELOG.md
buenaflor 1845eba
Fix analyze
buenaflor b15dcf8
try fix test
buenaflor 95d53f9
Update CHANGELOG.md
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:http/http.dart' show ClientException; | ||
import 'dart:async' show TimeoutException, AsyncError, DeferredLoadException; | ||
import '../sentry.dart'; | ||
|
||
import 'dart_exception_type_identifier_io.dart' | ||
if (dart.library.html) 'dart_exception_type_identifier_web.dart'; | ||
|
||
class DartExceptionTypeIdentifier implements ExceptionTypeIdentifier { | ||
@override | ||
String? identifyType(dynamic throwable) { | ||
// dart:core | ||
if (throwable is ArgumentError) return 'ArgumentError'; | ||
if (throwable is AssertionError) return 'AssertionError'; | ||
if (throwable is ConcurrentModificationError) { | ||
return 'ConcurrentModificationError'; | ||
} | ||
if (throwable is FormatException) return 'FormatException'; | ||
if (throwable is IndexError) return 'IndexError'; | ||
if (throwable is NoSuchMethodError) return 'NoSuchMethodError'; | ||
if (throwable is OutOfMemoryError) return 'OutOfMemoryError'; | ||
if (throwable is RangeError) return 'RangeError'; | ||
if (throwable is StackOverflowError) return 'StackOverflowError'; | ||
if (throwable is StateError) return 'StateError'; | ||
if (throwable is TypeError) return 'TypeError'; | ||
if (throwable is UnimplementedError) return 'UnimplementedError'; | ||
if (throwable is UnsupportedError) return 'UnsupportedError'; | ||
// not adding Exception or Error because it's too generic | ||
|
||
// dart:async | ||
if (throwable is TimeoutException) return 'TimeoutException'; | ||
if (throwable is AsyncError) return 'FutureTimeout'; | ||
if (throwable is DeferredLoadException) return 'DeferredLoadException'; | ||
// not adding ParallelWaitError because it's not supported in dart 2.17.0 | ||
|
||
// dart http package | ||
if (throwable is ClientException) return 'ClientException'; | ||
|
||
// platform specific exceptions | ||
return identifyPlatformSpecificException(throwable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
@internal | ||
String? identifyPlatformSpecificException(dynamic throwable) { | ||
if (throwable is FileSystemException) return 'FileSystemException'; | ||
if (throwable is HttpException) return 'HttpException'; | ||
if (throwable is SocketException) return 'SocketException'; | ||
if (throwable is HandshakeException) return 'HandshakeException'; | ||
if (throwable is CertificateException) return 'CertificateException'; | ||
if (throwable is TlsException) return 'TlsException'; | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
@internal | ||
String? identifyPlatformSpecificException(dynamic throwable) { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
/// An abstract class for identifying the type of Dart errors and exceptions. | ||
/// | ||
/// It's used in scenarios where error types need to be determined in obfuscated builds | ||
/// as [runtimeType] is not reliable in such cases. | ||
/// | ||
/// Implement this class to create custom error type identifiers for errors or exceptions. | ||
/// that we do not support out of the box. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// class MyExceptionTypeIdentifier implements ExceptionTypeIdentifier { | ||
/// @override | ||
/// String? identifyType(dynamic throwable) { | ||
/// if (throwable is MyCustomError) return 'MyCustomError'; | ||
/// return null; | ||
/// } | ||
/// } | ||
/// ``` | ||
abstract class ExceptionTypeIdentifier { | ||
String? identifyType(dynamic throwable); | ||
} | ||
|
||
extension CacheableExceptionIdentifier on ExceptionTypeIdentifier { | ||
ExceptionTypeIdentifier withCache() => CachingExceptionTypeIdentifier(this); | ||
} | ||
|
||
@visibleForTesting | ||
class CachingExceptionTypeIdentifier implements ExceptionTypeIdentifier { | ||
@visibleForTesting | ||
ExceptionTypeIdentifier get identifier => _identifier; | ||
final ExceptionTypeIdentifier _identifier; | ||
|
||
final Map<Type, String?> _knownExceptionTypes = {}; | ||
|
||
CachingExceptionTypeIdentifier(this._identifier); | ||
|
||
@override | ||
String? identifyType(dynamic throwable) { | ||
final runtimeType = throwable.runtimeType; | ||
if (_knownExceptionTypes.containsKey(runtimeType)) { | ||
return _knownExceptionTypes[runtimeType]; | ||
} | ||
|
||
final identifiedType = _identifier.identifyType(throwable); | ||
|
||
if (identifiedType != null) { | ||
_knownExceptionTypes[runtimeType] = identifiedType; | ||
} | ||
|
||
return identifiedType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's great that we have this option 👍 I would put this note one bullet above, so that it's connected to the callout about being opt out and that it changes (fixes!) grouping