I am trying to use the Chain object provided by stack_trace as follows:
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 output stack trace should include testFunction, but for some reason this is not the case. If I do this with futures, then:
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 a more expected result:
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 the chain incompatible with all asynchronous / pending?
source share