|
5 | 5 | import 'dart:async'; |
6 | 6 |
|
7 | 7 | import 'package:gcloud/storage.dart'; |
| 8 | +import 'package:stack_trace/stack_trace.dart'; |
| 9 | + |
| 10 | +const _skippedFirstFrames = { |
| 11 | + 'package:fake_gcloud/retry_enforcer_storage.dart', |
| 12 | + 'package:pub_dev/shared/storage.dart', |
| 13 | +}; |
8 | 14 |
|
9 | 15 | void _verifyRetryOnStack() { |
10 | 16 | final st = StackTrace.current.toString(); |
11 | | - if (st.contains('package:retry/')) return; |
12 | | - if (st.contains('retryAsync')) return; // lib/shared/utils.dart |
| 17 | + final trace = Trace.current(); |
| 18 | + |
| 19 | + // The first frame index outside of this file. |
| 20 | + var startFrameIndex = 0; |
| 21 | + while (_skippedFirstFrames.any((skipped) => |
| 22 | + trace.frames[startFrameIndex].uri.toString().contains(skipped))) { |
| 23 | + startFrameIndex++; |
| 24 | + } |
| 25 | + |
| 26 | + final firstRealFrame = |
| 27 | + trace.frames.skip(startFrameIndex).firstOrNull?.toString(); |
| 28 | + if (firstRealFrame == null) { |
| 29 | + return; |
| 30 | + } |
13 | 31 |
|
14 | 32 | // detect direct test calls |
15 | | - final linesWithoutThisFile = st |
16 | | - .split('\n') |
17 | | - .where((l) => !l.contains('retry_enforcer_storage.dart')) |
18 | | - .toList(); |
19 | | - if (linesWithoutThisFile.isNotEmpty && |
20 | | - linesWithoutThisFile.first.contains('_test.dart')) { |
| 33 | + if (firstRealFrame.contains('_test.dart')) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + // detect retry library |
| 38 | + if (firstRealFrame.contains('package:retry/')) { |
| 39 | + return; |
| 40 | + } |
| 41 | + // detect lib/shared/utils.dart use |
| 42 | + if (firstRealFrame.contains('retryAsync')) { |
21 | 43 | return; |
22 | 44 | } |
23 | 45 |
|
|
0 commit comments