Put the token pos errors behind a debug flag (dart-lang/coverage#395)
* Put the token pos errors behind a debug flag
These errors are not useful to users, and can be spammy.
* Get debug flag from environment
diff --git a/pkgs/coverage/lib/src/collect.dart b/pkgs/coverage/lib/src/collect.dart
index a2249a7..f23783f 100644
--- a/pkgs/coverage/lib/src/collect.dart
+++ b/pkgs/coverage/lib/src/collect.dart
@@ -11,6 +11,7 @@
import 'hitmap.dart';
const _retryInterval = Duration(milliseconds: 200);
+const _debugTokenPositions = bool.fromEnvironment('DEBUG_COVERAGE');
/// Collects coverage for all isolates in the running VM.
///
@@ -264,9 +265,11 @@
final line = _getLineFromTokenPos(script, tokenPos);
if (line == null) {
- stderr.writeln(
- 'tokenPos $tokenPos in function ${funcRef.name} has no line mapping '
- 'for script ${script.uri!}');
+ if (_debugTokenPositions) {
+ stderr.writeln(
+ 'tokenPos $tokenPos in function ${funcRef.name} has no line '
+ 'mapping for script ${script.uri!}');
+ }
return;
}
hits.funcNames![line] = funcName;
@@ -345,8 +348,10 @@
for (final pos in tokenPositions) {
final line = reportLines ? pos : _getLineFromTokenPos(script!, pos);
if (line == null) {
- stderr
- .write('tokenPos $pos has no line mapping for script $scriptUri');
+ if (_debugTokenPositions) {
+ stderr.write(
+ 'tokenPos $pos has no line mapping for script $scriptUri');
+ }
continue;
}
body(line);