Skip to main content

async_return_with_no_await

Details about the 'async_return_with_no_await' diagnostic produced by the Dart analyzer.

Returning a 'Future' without 'await'.

Description

#

The analyzer produces this diagnostic when a Future is returned from an async function without using await.

Returning an unawaited Future from an async function means any exception thrown by the Future might not propagate as expected. Having the exception thrown at the await site helps identify the source of the exception and makes it easier to debug.

Example

#

The following code produces this diagnostic because it returns the Future from futureString without using await:

dart
Future<String> futureString(Future<String> value) async {
  return value;
}

Common fixes

#

Add await before the returned Future:

dart
Future<String> futureString(Future<String> value) async {
  return await value;
}

If you don't need to use await, then remove async from the function body:

dart
Future<String> futureString(Future<String> value) {
  return value;
}