Skip to content

Instantly share code, notes, and snippets.

@talamaska
Created August 19, 2021 08:12
Show Gist options
  • Save talamaska/6805aa686f2ac4d0a6a7491974d5da2d to your computer and use it in GitHub Desktop.
Save talamaska/6805aa686f2ac4d0a6a7491974d5da2d to your computer and use it in GitHub Desktop.
The aim of waitForEx is to repair the stack trace the users sees the 'expected' stack trace rather than the microtask stack trace.
T waitForEx<T>(Future<T> future) {
Exception exception;
T value;
try {
value = cli.waitFor<T>(future);
}
// ignore: avoid_catching_errors
on AsyncError catch (e) {
if (e.error is Exception) {
exception = e.error as Exception;
} else {
Settings().verbose('Rethrowing a non DCliException $e');
rethrow;
}
}
if (exception != null) {
// recreate the exception so we have a full
// stacktrace rather than the microtask
// stacktrace the future leaves us with.
final stackTrace = StackTraceImpl(skipFrames: 2);
if (exception is DCliException) {
throw exception.copyWith(stackTrace);
} else {
/// Want to change this so we can throw the original exception with the repaired stack trace.
throw DCliException.from(exception, stackTrace);
}
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment