Skip to content
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

Fix newly surface errors after cleanup #64

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions lib/src/chain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Chain implements StackTrace {
}

if (!when) {
void Function(Object, StackTrace) newOnError;
late void Function(Object, StackTrace) newOnError;
if (onError != null) {
void wrappedOnError(Object error, StackTrace? stackTrace) {
onError(
Expand All @@ -102,7 +102,7 @@ class Chain implements StackTrace {
return runZoned(() {
try {
return callback();
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
natebosch marked this conversation as resolved.
Show resolved Hide resolved
// TODO(nweiz): Don't special-case this when issue 19566 is fixed.
Zone.current.handleUncaughtError(error, stackTrace);

Expand Down
14 changes: 7 additions & 7 deletions lib/src/frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Frame {
Frame parseLocation(String location, String member) {
var evalMatch = _v8EvalLocation.firstMatch(location);
while (evalMatch != null) {
location = evalMatch[1];
location = evalMatch[1]!;
evalMatch = _v8EvalLocation.firstMatch(location);
}

Expand All @@ -189,15 +189,15 @@ class Frame {
// lists anonymous functions within eval as "<anonymous>", while IE10
// lists them as "Anonymous function".
return parseLocation(
match[2],
match[2]!,
match[1]!
.replaceAll('<anonymous>', '<fn>')
.replaceAll('Anonymous function', '<fn>')
.replaceAll('(anonymous function)', '<fn>'));
} else {
// The second form looks like " at LOCATION", and is used for
// anonymous functions.
return parseLocation(match[3], '<fn>');
return parseLocation(match[3]!, '<fn>');
}
});

Expand All @@ -219,9 +219,9 @@ class Frame {
_catchFormatException(frame, () {
final match = _firefoxEvalLocation.firstMatch(frame);
if (match == null) return UnparsedFrame(frame);
var member = match[1].replaceAll('/<', '');
final uri = _uriOrPathToUri(match[2]);
final line = int.parse(match[3]);
var member = match[1]!.replaceAll('/<', '');
final uri = _uriOrPathToUri(match[2]!);
final line = int.parse(match[3]!);
if (member.isEmpty || member == 'anonymous') {
member = '<fn>';
}
Expand All @@ -233,7 +233,7 @@ class Frame {
var match = _firefoxSafariFrame.firstMatch(frame);
if (match == null) return UnparsedFrame(frame);

if (match[3].contains(' line ')) {
if (match[3]!.contains(' line ')) {
return Frame._parseFirefoxEval(frame);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/stack_zone_specification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'trace.dart';
import 'utils.dart';

/// A function that handles errors in the zone wrapped by [Chain.capture].
typedef _ChainHandler = void Function(dynamic error, Chain chain);
typedef _ChainHandler = void Function(Object error, Chain chain);

/// A class encapsulating the zone specification for a [Chain.capture] zone.
///
Expand Down Expand Up @@ -144,8 +144,8 @@ class StackZoneSpecification {

/// Looks up the chain associated with [stackTrace] and passes it either to
/// [_onError] or [parent]'s error handler.
void _handleUncaughtError(
Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) {
void _handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
Object error, StackTrace stackTrace) {
if (_disabled) {
parent.handleUncaughtError(zone, error, stackTrace);
return;
Expand All @@ -163,7 +163,7 @@ class StackZoneSpecification {
// TODO(rnystrom): Is the null-assertion correct here? It is nullable in
// Zone. Should we check for that here?
self.parent!.runBinary(_onError!, error, stackChain);
} catch (newError, newStackTrace) {
} on Object catch (newError, newStackTrace) {
if (identical(newError, error)) {
parent.handleUncaughtError(zone, error, stackChain);
} else {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: A package for manipulating stack traces and printing them readably.
homepage: https://github.com/dart-lang/stack_trace

environment:
sdk: '>=2.8.0-dev.10 <3.0.0'
sdk: '>=2.9.0-dev <3.0.0'

dependencies:
path: ^1.2.0
Expand Down
8 changes: 4 additions & 4 deletions test/chain/dart2js_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void main() {
expect(chain.traces, hasLength(2));
completer.complete();
}
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand Down Expand Up @@ -146,15 +146,15 @@ void main() {
}, onError: (error, chain) {
expect(error, equals('error'));
expect(chain.traces, hasLength(2));
throw error;
throw error as Object;
});
}, onError: (error, chain) {
try {
expect(error, equals('error'));
expect(chain, isA<Chain>());
expect(chain.traces, hasLength(2));
completer.complete();
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand All @@ -174,7 +174,7 @@ void main() {
expect(chain, isA<Chain>());
expect(chain.traces, hasLength(2));
completer.complete();
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand Down
10 changes: 5 additions & 5 deletions test/chain/vm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void main() {
contains(frameMember(startsWith('inPeriodicTimer'))));
completer.complete();
}
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand Down Expand Up @@ -241,7 +241,7 @@ void main() {
expect(error, equals('error'));
expect(chain.traces[1].frames,
contains(frameMember(startsWith('inMicrotask'))));
throw error;
throw error as Object;
});
}, onError: (error, chain) {
try {
Expand All @@ -250,7 +250,7 @@ void main() {
expect(chain.traces[1].frames,
contains(frameMember(startsWith('inMicrotask'))));
completer.complete();
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand All @@ -271,7 +271,7 @@ void main() {
expect(chain.traces[1].frames,
contains(frameMember(startsWith('inMicrotask'))));
completer.complete();
} catch (error, stackTrace) {
} on Object catch (error, stackTrace) {
completer.completeError(error, stackTrace);
}
});
Expand Down Expand Up @@ -481,7 +481,7 @@ void main() {
'chain', () {
// Disable the test package's chain-tracking.
return Chain.disable(() async {
StackTrace trace;
late StackTrace trace;
await Chain.capture(() async {
try {
throw 'error';
Expand Down