Skip to content

Instantly share code, notes, and snippets.

@kikuchy
Created April 4, 2019 08:22
Show Gist options
  • Save kikuchy/9fe3b219a66d198ac160f885463a48b3 to your computer and use it in GitHub Desktop.
Save kikuchy/9fe3b219a66d198ac160f885463a48b3 to your computer and use it in GitHub Desktop.
Is there any static code analyzer for Dart to detect Future#then's onError arguments?
void main() {
Future(() => throw Exception())
.then((i) => print(i),
// Statically, no issues found. But it causes RUNTIME error 👇
//
// Uncaught Error: TypeError: Closure 'main_closure1': type '() => void' is not a subtype of type '(Object) => dynamic'
onError: () => print("foo"));
Future(() => throw Exception())
.then((i) => print(i),
// Of course, no runtime error if onError has one or two arguments.
onError: (e) => print(e));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment