prefer-return-await
preset: recommended
Warns when a Future is returned from a try / catch block without an await
.
Not awaiting a Future leads to any potential exception to not be caught by the catch
block.
Example
❌ Bad:
Future<String> report(Iterable<String> records) async {
try {
// LINT: Returning the awaited 'Future' is necessary to ensure that any potential exception is caught by the try/catch block. Try awaiting it.
return anotherAsyncMethod();
} catch(e) {
print(e);
}
}
✅ Good:
Future<String> report(Iterable<String> records) async {
try {
return await anotherAsyncMethod();
} catch(e) {
print(e);
}
}