Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement analysis options suggested by pub (getsentry#46)
* Add pedantic and analysis options
* Fix analysis warnings
  • Loading branch information
yjbanov authored Oct 22, 2019
commit 240dc33b51f9a0ea2384ee865406c10d27f79597
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml
4 changes: 2 additions & 2 deletions bin/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<Null> main(List<String> rawArgs) async {
}

final String dsn = rawArgs.single;
final SentryClient client = new SentryClient(dsn: dsn);
final SentryClient client = SentryClient(dsn: dsn);

try {
await foo();
Expand Down Expand Up @@ -47,5 +47,5 @@ Future<Null> bar() async {
}

Future<Null> baz() async {
throw new StateError('This is a test error');
throw StateError('This is a test error');
}
84 changes: 55 additions & 29 deletions lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SentryClient {
dynamic clock,
UuidGenerator uuidGenerator,
}) {
httpClient ??= new Client();
httpClient ??= Client();
clock ??= _getUtcDateTime;
uuidGenerator ??= _generateUuidV4WithoutDashes;
compressPayload ??= true;
Expand All @@ -76,9 +76,11 @@ class SentryClient {
final List<String> userInfo = uri.userInfo.split(':');

assert(() {
if (uri.pathSegments.isEmpty)
throw new ArgumentError(
'Project ID not found in the URI path of the DSN URI: $dsn');
if (uri.pathSegments.isEmpty) {
throw ArgumentError(
'Project ID not found in the URI path of the DSN URI: $dsn',
);
}

return true;
}());
Expand All @@ -87,7 +89,7 @@ class SentryClient {
final String secretKey = userInfo.length >= 2 ? userInfo[1] : null;
final String projectId = uri.pathSegments.last;

return new SentryClient._(
return SentryClient._(
httpClient: httpClient,
clock: clockProvider,
uuidGenerator: uuidGenerator,
Expand Down Expand Up @@ -201,8 +203,9 @@ class SentryClient {
'logger': defaultLoggerName,
};

if (environmentAttributes != null)
if (environmentAttributes != null) {
mergeAttributes(environmentAttributes.toJson(), into: data);
}

// Merge the user context.
if (userContext != null) {
Expand All @@ -223,13 +226,14 @@ class SentryClient {
if (response.statusCode != 200) {
String errorMessage =
'Sentry.io responded with HTTP ${response.statusCode}';
if (response.headers['x-sentry-error'] != null)
if (response.headers['x-sentry-error'] != null) {
errorMessage += ': ${response.headers['x-sentry-error']}';
return new SentryResponse.failure(errorMessage);
}
return SentryResponse.failure(errorMessage);
}

final String eventId = json.decode(response.body)['id'];
return new SentryResponse.success(eventId: eventId);
return SentryResponse.success(eventId: eventId);
}

/// Reports the [exception] and optionally its [stackTrace] to Sentry.io.
Expand All @@ -241,7 +245,7 @@ class SentryClient {
dynamic stackTrace,
StackFrameFilter stackFrameFilter,
}) {
final Event event = new Event(
final Event event = Event(
exception: exception,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -284,16 +288,16 @@ class SentryResponse {
typedef UuidGenerator = String Function();

String _generateUuidV4WithoutDashes() =>
new Uuid().generateV4().replaceAll('-', '');
Uuid().generateV4().replaceAll('-', '');

/// Severity of the logged [Event].
@immutable
class SeverityLevel {
static const fatal = const SeverityLevel._('fatal');
static const error = const SeverityLevel._('error');
static const warning = const SeverityLevel._('warning');
static const info = const SeverityLevel._('info');
static const debug = const SeverityLevel._('debug');
static const fatal = SeverityLevel._('fatal');
static const error = SeverityLevel._('error');
static const warning = SeverityLevel._('warning');
static const info = SeverityLevel._('info');
static const debug = SeverityLevel._('debug');

const SeverityLevel._(this.name);

Expand All @@ -303,7 +307,7 @@ class SeverityLevel {

/// Sentry does not take a timezone and instead expects the date-time to be
/// submitted in UTC timezone.
DateTime _getUtcDateTime() => new DateTime.now().toUtc();
DateTime _getUtcDateTime() => DateTime.now().toUtc();

/// An event to be reported to Sentry.io.
@immutable
Expand Down Expand Up @@ -418,17 +422,29 @@ class Event {
},
};

if (loggerName != null) json['logger'] = loggerName;
if (loggerName != null) {
json['logger'] = loggerName;
}

if (serverName != null) json['server_name'] = serverName;
if (serverName != null) {
json['server_name'] = serverName;
}

if (release != null) json['release'] = release;
if (release != null) {
json['release'] = release;
}

if (environment != null) json['environment'] = environment;
if (environment != null) {
json['environment'] = environment;
}

if (message != null) json['message'] = message;
if (message != null) {
json['message'] = message;
}

if (transaction != null) json['transaction'] = transaction;
if (transaction != null) {
json['transaction'] = transaction;
}

if (exception != null) {
json['exception'] = [
Expand All @@ -446,21 +462,31 @@ class Event {
};
}

if (level != null) json['level'] = level.name;
if (level != null) {
json['level'] = level.name;
}

if (culprit != null) json['culprit'] = culprit;
if (culprit != null) {
json['culprit'] = culprit;
}

if (tags != null && tags.isNotEmpty) json['tags'] = tags;
if (tags != null && tags.isNotEmpty) {
json['tags'] = tags;
}

if (extra != null && extra.isNotEmpty) json['extra'] = extra;
if (extra != null && extra.isNotEmpty) {
json['extra'] = extra;
}

Map<String, dynamic> userContextMap;
if (userContext != null &&
(userContextMap = userContext.toJson()).isNotEmpty)
(userContextMap = userContext.toJson()).isNotEmpty) {
json['user'] = userContextMap;
}

if (fingerprint != null && fingerprint.isNotEmpty)
if (fingerprint != null && fingerprint.isNotEmpty) {
json['fingerprint'] = fingerprint;
}

if (breadcrumbs != null && breadcrumbs.isNotEmpty) {
json['breadcrumbs'] = <String, List<Map<String, dynamic>>>{
Expand Down
12 changes: 7 additions & 5 deletions lib/src/stack_trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef StackFrameFilter = List<Map<String, dynamic>> Function(

/// Sentry.io JSON encoding of a stack frame for the asynchronous suspension,
/// which is the gap between asynchronous calls.
const Map<String, dynamic> asynchronousGapFrameJson = const <String, dynamic>{
const Map<String, dynamic> asynchronousGapFrameJson = <String, dynamic>{
'abs_path': '<asynchronous suspension>',
};

Expand All @@ -27,8 +27,8 @@ List<Map<String, dynamic>> encodeStackTrace(dynamic stackTrace,
{StackFrameFilter stackFrameFilter}) {
assert(stackTrace is String || stackTrace is StackTrace);
final Chain chain = stackTrace is StackTrace
? new Chain.forTrace(stackTrace)
: new Chain.parse(stackTrace);
? Chain.forTrace(stackTrace)
: Chain.parse(stackTrace);

final List<Map<String, dynamic>> frames = <Map<String, dynamic>>[];
for (int t = 0; t < chain.traces.length; t += 1) {
Expand All @@ -48,8 +48,9 @@ Map<String, dynamic> encodeStackTraceFrame(Frame frame) {
'in_app': !frame.isCore,
};

if (frame.uri.pathSegments.isNotEmpty)
if (frame.uri.pathSegments.isNotEmpty) {
json['filename'] = frame.uri.pathSegments.last;
}

return json;
}
Expand All @@ -63,8 +64,9 @@ Map<String, dynamic> encodeStackTraceFrame(Frame frame) {
/// "dart:" and "package:" imports are always relative and are OK to send in
/// full.
String _absolutePathForCrashReport(Frame frame) {
if (frame.uri.scheme != 'dart' && frame.uri.scheme != 'package')
if (frame.uri.scheme != 'dart' && frame.uri.scheme != 'package') {
return frame.uri.pathSegments.last;
}

return '${frame.uri}';
}
3 changes: 2 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void mergeAttributes(Map<String, dynamic> attributes,
String formatDateAsIso8601WithSecondPrecision(DateTime date) {
String iso = date.toIso8601String();
final millisecondSeparatorIndex = iso.lastIndexOf('.');
if (millisecondSeparatorIndex != -1)
if (millisecondSeparatorIndex != -1) {
iso = iso.substring(0, millisecondSeparatorIndex);
}
return iso;
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
meta: ">=1.0.0 <2.0.0"
stack_trace: ">=1.0.0 <2.0.0"
usage: ">=3.0.0 <4.0.0"
pedantic: ">=1.8.0 <2.0.0"

dev_dependencies:
args: ">=0.13.0 <2.0.0"
Expand Down
Loading