Skip to content

Commit 8e3ff29

Browse files
authored
Update async/await guideline to not break other guideline (#6559)
Resolves #3132
1 parent 084e070 commit 8e3ff29

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

examples/misc/lib/effective_dart/usage_bad.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class BadTeam extends Team {
315315
return players.where((player) => player.isActive).length;
316316
});
317317
})
318-
.catchError((e) {
318+
.onError<DownloadException>((e, _) {
319319
log.error(e);
320320
return 0;
321321
});

examples/misc/lib/effective_dart/usage_good.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ class Player {
319319
bool get isActive => false;
320320
}
321321

322+
class DownloadException implements Exception {}
323+
322324
class Team {
323325
Future<List<Player>> get roster => Future.value([]);
324326
Future<Team?> downloadTeam(String name) => Future.value(Team());
@@ -332,7 +334,7 @@ class Team {
332334

333335
var players = await team.roster;
334336
return players.where((player) => player.isActive).length;
335-
} catch (e) {
337+
} on DownloadException catch (e, _) {
336338
log.error(e);
337339
return 0;
338340
}

src/content/effective-dart/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ Future<int> countActivePlayers(String teamName) [!async!] {
15641564
15651565
var players = [!await!] team.roster;
15661566
return players.where((player) => player.isActive).length;
1567-
} catch (e) {
1567+
} on DownloadException catch (e, _) {
15681568
log.error(e);
15691569
return 0;
15701570
}
@@ -1582,7 +1582,7 @@ Future<int> countActivePlayers(String teamName) {
15821582
return players.where((player) => player.isActive).length;
15831583
});
15841584
})
1585-
.catchError((e) {
1585+
.onError<DownloadException>((e, _) {
15861586
log.error(e);
15871587
return 0;
15881588
});

0 commit comments

Comments
 (0)