Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
902dd1d
add options.attachStacktrace
rxlabz Nov 10, 2020
e1f347d
fix case
rxlabz Nov 10, 2020
07048d5
add a _exceptionFactory.stacktraceFactory getter
rxlabz Nov 10, 2020
a61f760
- auto-attach stacktrace to exception only if options.attachStackTrace
rxlabz Nov 10, 2020
0a5addb
fix test
rxlabz Nov 10, 2020
f7f2458
add client._stackTraceFactory
rxlabz Nov 10, 2020
a526771
fix import
rxlabz Nov 10, 2020
3c6cd02
attach stacktrace only if frames is not empty
rxlabz Nov 10, 2020
65c4d2b
attachStackTrace doc
rxlabz Nov 10, 2020
6d349fc
attachStackTrace only if event.stacktrace is null
rxlabz Nov 10, 2020
23738c2
init factories in client.ctor
rxlabz Nov 10, 2020
cbb7be8
feedback
rxlabz Nov 10, 2020
ee39da9
required SentryExceptionFactory.stacktraceFactory
rxlabz Nov 10, 2020
d901e26
type SentryEvent.stackTrace as SentryStackTrace
rxlabz Nov 11, 2020
490d3b7
serialize exception or stacktrace
rxlabz Nov 11, 2020
75d69a6
feedback
rxlabz Nov 11, 2020
b0c4a8e
feedbacks
rxlabz Nov 11, 2020
a027fe8
attach stacktrace only if stacktrace is null
rxlabz Nov 11, 2020
b92f661
event.stacktrace only if event.throwable AND event.exception are null
rxlabz Nov 11, 2020
7f4d18e
remove null conditional instanciation in exceptionFactory
rxlabz Nov 11, 2020
b3f546d
attach the passed stacktrace if attachStackTrace is true
rxlabz Nov 11, 2020
67c9ae8
fix & refactor client._prepareEvent
rxlabz Nov 11, 2020
c65800e
add stacktrace and exception.stacktrace tests
rxlabz Nov 11, 2020
ac1ee38
feedbacks
rxlabz Nov 11, 2020
3077703
fix frame.uri.pathSegments.isNotEmpty
rxlabz Nov 12, 2020
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
Prev Previous commit
Next Next commit
add stacktrace and exception.stacktrace tests
  • Loading branch information
rxlabz committed Nov 11, 2020
commit c65800eebaa712c8f16e761ea05bd33be022cb46
8 changes: 4 additions & 4 deletions dart/lib/src/protocol/sentry_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SentryException {
final String module;

/// An optional stack trace object
final SentryStackTrace stacktrace;
final SentryStackTrace stackTrace;

/// An optional object describing the [Mechanism] that created this exception
final Mechanism mechanism;
Expand All @@ -26,7 +26,7 @@ class SentryException {
@required this.type,
@required this.value,
this.module,
this.stacktrace,
this.stackTrace,
this.mechanism,
this.threadId,
});
Expand All @@ -46,8 +46,8 @@ class SentryException {
json['module'] = module;
}

if (stacktrace != null) {
json['stacktrace'] = stacktrace.toJson();
if (stackTrace != null) {
json['stacktrace'] = stackTrace.toJson();
}

if (mechanism != null) {
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SentryExceptionFactory {
type: '${exception.runtimeType}',
value: '$exception',
mechanism: mechanism,
stacktrace: sentryStackTrace,
stackTrace: sentryStackTrace,
);

return sentryException;
Expand Down
8 changes: 4 additions & 4 deletions dart/test/exception_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
}

expect(sentryException.type, 'StateError');
expect(sentryException.stacktrace.frames, isNotEmpty);
expect(sentryException.stackTrace.frames, isNotEmpty);
});

test('should not override event.stacktrace', () {
Expand All @@ -51,9 +51,9 @@ void main() {
}

expect(sentryException.type, 'StateError');
expect(sentryException.stacktrace.frames.first.lineNo, 46);
expect(sentryException.stacktrace.frames.first.colNo, 9);
expect(sentryException.stacktrace.frames.first.fileName, 'test.dart');
expect(sentryException.stackTrace.frames.first.lineNo, 46);
expect(sentryException.stackTrace.frames.first.colNo, 9);
expect(sentryException.stackTrace.frames.first.fileName, 'test.dart');
});
});

Expand Down
2 changes: 1 addition & 1 deletion dart/test/protocol/sentry_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() {
type: 'StateError',
value: 'Bad state: error',
module: 'example.module',
stacktrace: stacktrace,
stackTrace: stacktrace,
mechanism: mechanism,
threadId: 123456,
);
Expand Down
111 changes: 100 additions & 11 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:mockito/mockito.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/sentry_stack_trace_factory.dart';
import 'package:test/test.dart';

import 'mocks.dart';
Expand All @@ -13,6 +14,94 @@ void main() {
options.transport = MockTransport();
});

test('should capture event stacktrace', () async {
final client = SentryClient(options..attachStackTrace = false);
final event = SentryEvent();
await client.captureEvent(
event,
stackTrace: '#0 baz (file:///pathto/test.dart:50:3)',
);

final capturedEvent = (verify(
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.stackTrace is SentryStackTrace, true);
});

test('should attach event stacktrace', () async {
final client = SentryClient(options);
final event = SentryEvent();
await client.captureEvent(event);

final capturedEvent = (verify(
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.stackTrace is SentryStackTrace, true);
});

test('should not attach event stacktrace', () async {
final client = SentryClient(options..attachStackTrace = false);
final event = SentryEvent();
await client.captureEvent(event);

final capturedEvent = (verify(
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.stackTrace, isNull);
});

test('should not attach event stacktrace if event has throwable', () async {
final client = SentryClient(options);

SentryEvent event;
try {
throw StateError('Error');
} on Error catch (err) {
event = SentryEvent(throwable: err);
}

await client.captureEvent(
event,
stackTrace: '#0 baz (file:///pathto/test.dart:50:3)',
);

final capturedEvent = (verify(
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.stackTrace, isNull);
expect(capturedEvent.exception.stackTrace, isNotNull);
});

test('should not attach event stacktrace if event has exception', () async {
final client = SentryClient(options);

final exception = SentryException(
type: 'Exception',
value: 'an exception',
stackTrace: SentryStackTrace(
frames: SentryStackTraceFactory(options)
.getStackFrames('#0 baz (file:///pathto/test.dart:50:3)'),
),
);
final event = SentryEvent(exception: exception);

await client.captureEvent(
event,
stackTrace: '#0 baz (file:///pathto/test.dart:50:3)',
);

final capturedEvent = (verify(
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.stackTrace, isNull);
expect(capturedEvent.exception.stackTrace, isNotNull);
});

test('should capture message', () async {
final client = SentryClient(options);
await client.captureMessage(
Expand Down Expand Up @@ -73,7 +162,7 @@ void main() {

expect(capturedEvent.throwable, error);
expect(capturedEvent.exception is SentryException, true);
expect(capturedEvent.exception.stacktrace, isNotNull);
expect(capturedEvent.exception.stackTrace, isNotNull);
});
});

Expand Down Expand Up @@ -109,11 +198,11 @@ void main() {

expect(capturedEvent.throwable, error);
expect(capturedEvent.exception is SentryException, true);
expect(capturedEvent.exception.stacktrace, isNotNull);
expect(capturedEvent.exception.stacktrace.frames.first.fileName,
expect(capturedEvent.exception.stackTrace, isNotNull);
expect(capturedEvent.exception.stackTrace.frames.first.fileName,
'test.dart');
expect(capturedEvent.exception.stacktrace.frames.first.lineNo, 46);
expect(capturedEvent.exception.stacktrace.frames.first.colNo, 9);
expect(capturedEvent.exception.stackTrace.frames.first.lineNo, 46);
expect(capturedEvent.exception.stackTrace.frames.first.colNo, 9);
});
});

Expand Down Expand Up @@ -149,10 +238,10 @@ void main() {

expect(capturedEvent.throwable, exception);
expect(capturedEvent.exception is SentryException, true);
expect(capturedEvent.exception.stacktrace.frames.first.fileName,
expect(capturedEvent.exception.stackTrace.frames.first.fileName,
'test.dart');
expect(capturedEvent.exception.stacktrace.frames.first.lineNo, 46);
expect(capturedEvent.exception.stacktrace.frames.first.colNo, 9);
expect(capturedEvent.exception.stackTrace.frames.first.lineNo, 46);
expect(capturedEvent.exception.stackTrace.frames.first.colNo, 9);
});

test('should capture exception with Stackframe.current', () async {
Expand All @@ -169,7 +258,7 @@ void main() {
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.exception.stacktrace, isNotNull);
expect(capturedEvent.exception.stackTrace, isNotNull);
});

test('should capture exception without Stackframe.current', () async {
Expand All @@ -186,7 +275,7 @@ void main() {
options.transport.send(captureAny),
).captured.first) as SentryEvent;

expect(capturedEvent.exception.stacktrace, isNull);
expect(capturedEvent.exception.stackTrace, isNull);
});

test('should not capture sentry frames exception', () async {
Expand All @@ -211,7 +300,7 @@ void main() {
).captured.first) as SentryEvent;

expect(
capturedEvent.exception.stacktrace.frames
capturedEvent.exception.stackTrace.frames
.every((frame) => frame.package != 'sentry'),
true,
);
Expand Down