Skip to content

Commit

Permalink
Merge pull request #15 from WideSpectrumComputing/null-safety
Browse files Browse the repository at this point in the history
Null safety
  • Loading branch information
akornich authored Dec 21, 2021
2 parents 8946a0b + dd7d90c commit 33f18af
Show file tree
Hide file tree
Showing 43 changed files with 446 additions and 277 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Flutter version ${{ matrix.flutter_version }}
strategy:
matrix:
flutter_version: ['2.0.5', '1.20.4', '2.5.1']
flutter_version: ['2.0.6', '2.2.3', '2.5.3', '2.8.0']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
name: Flutter version ${{ matrix.flutter_version }} (iOS)
strategy:
matrix:
flutter_version: ['1.20.4', '2.5.1']
flutter_version: ['2.0.6', '2.2.3', '2.5.3', '2.8.0']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local.properties
**/pana-report
**/.pubignore

**/.DS_Store
14 changes: 0 additions & 14 deletions analysis_options.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion rollbar_dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.1.0-beta
## 0.2.0-beta
- Added null-safety.

## 0.1.0-beta
- Initial version of rollbar-dart.
1 change: 0 additions & 1 deletion rollbar_dart/analysis_options.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions rollbar_dart/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.

# include: package:lints/core.yaml
include: package:lints/recommended.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

linter:
rules:
- always_declare_return_types
- prefer_single_quotes
- sort_child_properties_last
- unawaited_futures
- unsafe_html
- use_full_hex_values_for_flutter_colors
# - cancel_subscriptions
# - close_sinks
# - comment_references
# - one_member_abstracts
# - only_throw_errors
# - package_api_docs
# - prefer_final_in_for_each

analyzer:
exclude:
- 'example/**'
1 change: 1 addition & 0 deletions rollbar_dart/lib/rollbar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library rollbar;

export 'src/logging.dart';
export 'src/rollbar.dart';
export 'src/config.dart';
export 'src/sender.dart';
Expand Down
26 changes: 13 additions & 13 deletions rollbar_dart/lib/src/api/payload/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'frame.dart';
/// Container class with the error or message to be sent to Rollbar.
abstract class Body {
Map<String, dynamic> toJson();
List<TraceInfo> getTraces();
List<TraceInfo?>? getTraces();

static Body empty() {
return Message()..body = '';
}

static Body fromMap(Map attributes) {
static Body? fromMap(Map attributes) {
if (attributes.containsKey('trace')) {
return TraceInfo.fromMap(attributes);
} else if (attributes.containsKey('message')) {
Expand All @@ -23,9 +23,9 @@ abstract class Body {

/// An individual error with its corresponding stack trace if available.
class TraceInfo implements Body {
List<Frame> frames;
ExceptionInfo exception;
String rawTrace;
late List<Frame> frames;
ExceptionInfo? exception;
String? rawTrace;

TraceInfo() {
frames = [];
Expand All @@ -45,7 +45,7 @@ class TraceInfo implements Body {
};

if (exception != null) {
traceInfo['trace']['exception'] = exception.toJson();
traceInfo['trace']['exception'] = exception!.toJson();
}

if (rawTrace != null) {
Expand All @@ -55,7 +55,7 @@ class TraceInfo implements Body {
return traceInfo;
}

static TraceInfo fromMap(Map attributes) {
static TraceInfo? fromMap(Map attributes) {
if (!attributes.containsKey('trace')) {
return null;
}
Expand Down Expand Up @@ -87,13 +87,13 @@ class TraceInfo implements Body {
/// A chain of multiple errors, where the first one on the list represents the
/// root cause of the error.
class TraceChain implements Body {
List<TraceInfo> traces;
List<TraceInfo?>? traces;

@override
Map<String, dynamic> toJson() {
return {
'trace_chain': traces.map((v) {
return v.toJson()['trace'];
'trace_chain': traces!.map((v) {
return v!.toJson()['trace'];
}).toList()
};
}
Expand All @@ -107,21 +107,21 @@ class TraceChain implements Body {
}

@override
List<TraceInfo> getTraces() {
List<TraceInfo?>? getTraces() {
return traces;
}
}

/// A text message to be sent to Rollbar.
class Message implements Body {
String body;
String? body;

@override
List<TraceInfo> getTraces() {
return [];
}

static Message fromMap(Map attributes) {
static Message? fromMap(Map attributes) {
if (!attributes.containsKey('message')) {
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions rollbar_dart/lib/src/api/payload/client.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Client {
String locale;
String? locale;

String hostname;
String? hostname;

String os;
String? os;

String osVersion;
String? osVersion;

String rootPackage;
String? rootPackage;

Map<String, String> dart;
Map<String, String>? dart;

/// Converts the object into a Json encodable map.
///
Expand Down
26 changes: 13 additions & 13 deletions rollbar_dart/lib/src/api/payload/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import 'level.dart';

/// Contains the data for the occurrence to be sent to Rollbar.
class Data {
Map<String, String> notifier;
String environment;
Client client;
String platform;
String language;
String framework;
String codeVersion;
Level level;
int timestamp;
Body body;
Map<String, Object> custom;
Map platformPayload;
Map server;
late Map<String, String> notifier;
String? environment;
late Client client;
String? platform;
late String language;
String? framework;
String? codeVersion;
Level? level;
int? timestamp;
late Body body;
Map<String, Object>? custom;
Map? platformPayload;
Map? server;

Map<String, dynamic> toJson() {
var result = {
Expand Down
6 changes: 3 additions & 3 deletions rollbar_dart/lib/src/api/payload/exception_info.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Contains all the error details except the stack trace.
class ExceptionInfo {
String clazz;
String message;
String description;
String? clazz;
String? message;
String? description;

Map<String, dynamic> toJson() {
var result = {'class': clazz, 'message': message};
Expand Down
14 changes: 7 additions & 7 deletions rollbar_dart/lib/src/api/payload/frame.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// Contains the information of a single frame in a stack trace.
class Frame {
int colno;
int lineno;
String method;
String filename;
String className;
int? colno;
int? lineno;
String? method;
String? filename;
String? className;

Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
Expand All @@ -29,10 +29,10 @@ class Frame {
static Frame fromMap(Map attributes) {
var result = Frame();
if (attributes.containsKey('colno')) {
result.colno = attributes['colno'] as int;
result.colno = attributes['colno'] as int?;
}
if (attributes.containsKey('lineno')) {
result.lineno = attributes['lineno'] as int;
result.lineno = attributes['lineno'] as int?;
}
if (attributes.containsKey('method')) {
result.method = attributes['method'];
Expand Down
7 changes: 4 additions & 3 deletions rollbar_dart/lib/src/api/payload/level.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// The level of an occurrence.
enum Level { debug, info, warning, error, critical }

extension LevelExtension on Level {
extension LevelExtension on Level? {
// The 'foundation' library, which contains `describeEnum`, is part of flutter,
// so we don't want to add it as a dependency in rollbar-dart.
String get name {
String? get name {
switch (this) {
case Level.debug:
return 'debug';
Expand All @@ -16,7 +16,8 @@ extension LevelExtension on Level {
return 'error';
case Level.critical:
return 'critical';
default:
return null;
}
return null;
}
}
4 changes: 2 additions & 2 deletions rollbar_dart/lib/src/api/payload/payload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'data.dart';
/// Represents the payload to be sent to Rollbar. A successfully constructed Payload matches Rollbar's
/// spec, and can be POSTed to the correct endpoint when serialized as JSON.
class Payload {
String accessToken;
Data data;
String? accessToken;
late Data data;

Map<String, dynamic> toJson() {
return {'access_token': accessToken, 'data': data.toJson()};
Expand Down
8 changes: 4 additions & 4 deletions rollbar_dart/lib/src/api/response.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/// Represents the response from the Rollbar API.
class Response {
int err;
String message;
Result result;
int? err;
String? message;
Result? result;

bool isError() {
return err != null && err != 0;
}
}

class Result {
String uuid;
String? uuid;
}
32 changes: 16 additions & 16 deletions rollbar_dart/lib/src/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:rollbar_dart/src/http_sender.dart';
import 'http_sender.dart';

import 'transformer.dart';
import 'sender.dart';
Expand All @@ -7,13 +7,13 @@ import 'sender.dart';
class Config {
final String accessToken;
final String endpoint;
final String environment;
final String framework;
final String codeVersion;
final String package;
final bool handleUncaughtErrors;
final bool includePlatformLogs;
final Transformer Function(Config) transformer;
final String? environment;
final String? framework;
final String? codeVersion;
final String? package;
final bool? handleUncaughtErrors;
final bool? includePlatformLogs;
final Transformer Function(Config)? transformer;
final Sender Function(Config) sender;

Config._(
Expand Down Expand Up @@ -66,23 +66,23 @@ class Config {
class ConfigBuilder {
final String accessToken;
String endpoint = 'https://api.rollbar.com/api/1/item/';
String environment;
String framework;
String codeVersion;
String package;
String? environment;
String? framework;
String? codeVersion;
String? package;

bool handleUncaughtErrors = false;
bool includePlatformLogs = false;
bool? handleUncaughtErrors = false;
bool? includePlatformLogs = false;

/// If [handleUncaughtErrors] is enabled, the transformer function *must* be a static
/// or free function, and cannot be a closure or instance function, since it will need
/// to be passed to an error handler isolate as a message.
Transformer Function(Config) transformer;
Transformer Function(Config)? transformer;

/// If [handleUncaughtErrors] is enabled, the sender factory *must* be a static
/// or free function, and cannot be a closure or instance function, since it will need
/// to be passed to an error handler isolate as a message.
Sender Function(Config) sender;
Sender Function(Config)? sender;

ConfigBuilder(this.accessToken);

Expand Down
Loading

0 comments on commit 33f18af

Please sign in to comment.