From fc32eb69f2ad666e9ab1cb3300510e5daed222d6 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 14 May 2024 14:02:39 -0700 Subject: [PATCH] Collect log message count and log at the end (#2430) --- dwds/lib/src/debugging/debugger.dart | 16 +++++++++++++--- dwds/lib/src/debugging/frame_computer.dart | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dwds/lib/src/debugging/debugger.dart b/dwds/lib/src/debugging/debugger.dart index 7e6d41824..678448569 100644 --- a/dwds/lib/src/debugging/debugger.dart +++ b/dwds/lib/src/debugging/debugger.dart @@ -54,6 +54,8 @@ class Debugger extends Domain { final Locations _locations; final SkipLists _skipLists; + int _frameErrorCount = 0; + Debugger._( this._remoteDebugger, this._streamNotify, @@ -465,15 +467,23 @@ class Debugger extends Domain { try { dartFrame.vars = await variablesFor(frame); } catch (e) { - logger.warning( - 'Error calculating Dart variables for frame $frameIndex: $e', - ); + _frameErrorCount++; } } return dartFrame; } + /// Can be called after [calculateDartFrameFor] to log any errors. + void logAnyFrameErrors({required String frameType}) { + if (_frameErrorCount > 0) { + logger.warning( + 'Error calculating Dart variables for $_frameErrorCount $frameType frames.', + ); + } + _frameErrorCount = 0; + } + void _scriptParsedHandler(ScriptParsedEvent e) { final scriptPath = _pathForChromeScript(e.script.url); if (scriptPath != null) { diff --git a/dwds/lib/src/debugging/frame_computer.dart b/dwds/lib/src/debugging/frame_computer.dart index 6626a0f81..ec642c669 100644 --- a/dwds/lib/src/debugging/frame_computer.dart +++ b/dwds/lib/src/debugging/frame_computer.dart @@ -73,6 +73,7 @@ class FrameComputer { logger.warning('Error calculating sync frame: $e'); } } + debugger.logAnyFrameErrors(frameType: 'sync'); } Future _collectAsyncFrames({int? limit}) async { @@ -129,6 +130,7 @@ class FrameComputer { logger.warning('Error calculating async frame: $e'); } } + debugger.logAnyFrameErrors(frameType: 'async'); } // Async frames are no longer on the stack - we don't have local variable