debugDrainErrors method

Future<String?> debugDrainErrors([
  1. String where = ''
])

Everything the browser complained about since the last drain, or null when it complained about nothing.

Asynchronous because the verdicts are: every scope guard opened is a promise, and this waits for the ones outstanding before answering. A test that draws and then asks gets the truth; a caller that never asks pays for the scopes and nothing else.

Implementation

Future<String?> debugDrainErrors([String where = '']) async {
  final outstanding = List<Future<void>>.of(_pending);
  _pending.clear();
  await Future.wait(outstanding);
  if (_errors.isEmpty) return null;
  final said = _errors.join('; ');
  _errors.clear();
  return where.isEmpty ? said : '$where: $said';
}