I'm trying to take advantage of the Chain object provided by stack_trace like so:
import 'dart:async';
import 'package:stack_trace/stack_trace.dart';
main() async {
print('Hello world: ${console_test.calculate()}!');
Chain.capture(() async {
try {
await testFunction();
} catch(e,st) {
print(Trace.format(new Chain.forTrace(st)));
}
});
}
Future testFunction() async {
throw new Exception("TEST");
}
The output I get is this:
Hello world: 42!
main.dart 4:1 main.<async>.<fn>.<async>
I understand that the outputted stack trace should include testFunction, but for some reason it isn't. If I do it with futures instead:
import 'dart:async';
import 'package:stack_trace/stack_trace.dart';
main() async {
print('Hello world: ${console_test.calculate()}!');
Chain.capture(() {
return testFunction();
}, onError: (e, stackTrace) => print(Trace.format(new Chain.forTrace(stackTrace))));
}
Future testFunction() async {
throw new Exception("TEST");
}
I get more expected output:
Hello world: 42!
main.dart 17:3 testFunction.<async>
dart:async _Completer.completeError
main.dart 4:1 testFunction.<async>
dart:async Future.Future
main.dart 4:1 testFunction
main.dart 11:26 main.<async>.<fn>
package:stack_trace Chain.capture
main.dart 10:16 main.<async>
Am I doing something wrong? Is Chain incompatible with the whole async/await thing?