-
-
Notifications
You must be signed in to change notification settings - Fork 257
Add SentryRequest context for HttpException and SocketException #1118
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dbce1fd
wip
ueman 462e54b
add tests and changelog
ueman 8854db2
Merge branch 'main' into improve-exceptions
ueman 3714a9e
Update CHANGELOG.md
ueman a810b4f
add test for SentryRequest.fromUri
ueman d3a1150
Merge branch 'main' into improve-exceptions
ueman 204d549
fix changelog
ueman 7e96fc1
set error code as posix signal
ueman f560768
change order of exceptions
ueman f88c405
Merge branch 'main' into improve-exceptions
ueman f1f2545
fix changelog
ueman 5294ee1
Merge branch 'main' into improve-exceptions
ueman 9473546
use errno
ueman 1c64cf3
network image exception
ueman d5d988e
add it by default
ueman dae529c
add changelog
ueman 2ad6523
PR feedback
ueman 7a03b83
Merge branch 'main' into improve-exceptions
ueman 62eb116
Merge branch 'main' into improve-exceptions
marandaneto 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 hidden or 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 was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
dart/lib/src/event_processor/enricher/enricher_event_processor.dart
This file contains hidden or 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,9 @@ | ||
import '../../event_processor.dart'; | ||
import '../../sentry_options.dart'; | ||
import 'io_enricher_event_processor.dart' | ||
if (dart.library.html) 'web_enricher_event_processor.dart'; | ||
|
||
abstract class EnricherEventProcessor implements EventProcessor { | ||
factory EnricherEventProcessor(SentryOptions options) => | ||
enricherEventProcessor(options); | ||
} |
This file contains hidden or 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
10 changes: 5 additions & 5 deletions
10
...nricher/web_enricher_event_processor.dart → ...nricher/web_enricher_event_processor.dart
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
dart/lib/src/event_processor/exception/exception_event_processor.dart
This file contains hidden or 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,7 @@ | ||
import '../../event_processor.dart'; | ||
import 'io_exception_event_processor.dart' | ||
if (dart.library.html) 'web_exception_event_processor.dart'; | ||
|
||
abstract class ExceptionEventProcessor implements EventProcessor { | ||
factory ExceptionEventProcessor() => exceptionEventProcessor(); | ||
} |
94 changes: 94 additions & 0 deletions
94
dart/lib/src/event_processor/exception/io_exception_event_processor.dart
This file contains hidden or 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,94 @@ | ||
import 'dart:io'; | ||
|
||
import '../../protocol.dart'; | ||
import 'exception_event_processor.dart'; | ||
|
||
ExceptionEventProcessor exceptionEventProcessor() => | ||
IoExceptionEventProcessor(); | ||
|
||
class IoExceptionEventProcessor implements ExceptionEventProcessor { | ||
@override | ||
SentryEvent apply(SentryEvent event, {dynamic hint}) { | ||
ueman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final throwable = event.throwable; | ||
if (throwable is HttpException) { | ||
return applyHttpException(throwable, event); | ||
} | ||
if (throwable is SocketException) { | ||
return applySocketException(throwable, event); | ||
} | ||
if (throwable is FileSystemException) { | ||
return applyFileSystemException(throwable, event); | ||
} | ||
|
||
return event; | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/HttpException-class.html | ||
SentryEvent applyHttpException(HttpException exception, SentryEvent event) { | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final uri = exception.uri; | ||
if (uri == null) { | ||
return event; | ||
} | ||
return event.copyWith( | ||
request: event.request ?? SentryRequest.fromUri(uri: uri), | ||
); | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/SocketException-class.html | ||
SentryEvent applySocketException( | ||
SocketException exception, | ||
SentryEvent event, | ||
) { | ||
final address = exception.address; | ||
if (address == null) { | ||
return event; | ||
} | ||
final osError = exception.osError; | ||
SentryRequest? request; | ||
try { | ||
var uri = Uri.parse(address.host); | ||
request = SentryRequest.fromUri(uri: uri); | ||
} catch (_) {} | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return event.copyWith( | ||
request: event.request ?? request, | ||
exceptions: [ | ||
...?event.exceptions, | ||
// OSError is the underlying error | ||
// https://api.dart.dev/stable/dart-io/SocketException/osError.html | ||
// https://api.dart.dev/stable/dart-io/OSError-class.html | ||
if (osError != null) _sentryExceptionfromOsError(osError), | ||
], | ||
); | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/FileSystemException-class.html | ||
SentryEvent applyFileSystemException( | ||
FileSystemException exception, | ||
SentryEvent event, | ||
) { | ||
final osError = exception.osError; | ||
return event.copyWith( | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exceptions: [ | ||
...?event.exceptions, | ||
// OSError is the underlying error | ||
// https://api.dart.dev/stable/dart-io/FileSystemException/osError.html | ||
// https://api.dart.dev/stable/dart-io/OSError-class.html | ||
if (osError != null) _sentryExceptionfromOsError(osError), | ||
], | ||
); | ||
} | ||
} | ||
|
||
SentryException _sentryExceptionfromOsError(OSError osError) { | ||
return SentryException( | ||
type: osError.runtimeType.toString(), | ||
value: osError.toString(), | ||
mechanism: Mechanism( | ||
type: 'OSError', | ||
meta: { | ||
'code': osError.errorCode, | ||
}, | ||
), | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
dart/lib/src/event_processor/exception/web_exception_event_processor.dart
This file contains hidden or 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,10 @@ | ||
import '../../protocol.dart'; | ||
import 'exception_event_processor.dart'; | ||
|
||
ExceptionEventProcessor exceptionEventProcessor() => | ||
WebExcptionEventProcessor(); | ||
|
||
class WebExcptionEventProcessor implements ExceptionEventProcessor { | ||
@override | ||
SentryEvent apply(SentryEvent event, {dynamic hint}) => event; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
6 changes: 3 additions & 3 deletions
6
dart/test/enricher/io_enricher_test.dart → ..._processor/enricher/io_enricher_test.dart
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.