@@ -1363,8 +1363,6 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
13631363
13641364 final args = event.args;
13651365 final firstArgValue = (args.isNotEmpty ? args[0 ].value : null ) as String ? ;
1366- // TODO(nshahan) - Migrate 'inspect' and 'log' events to the injected
1367- // client communication approach as well?
13681366 switch (firstArgValue) {
13691367 case 'dart.developer.inspect' :
13701368 // All inspected objects should be real objects.
@@ -1383,7 +1381,13 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
13831381 );
13841382 break ;
13851383 case 'dart.developer.log' :
1386- await _handleDeveloperLog (isolateRef, event);
1384+ await _handleDeveloperLog (isolateRef, event).catchError (
1385+ (error, stackTrace) => _logger.warning (
1386+ 'Error handling developer log:' ,
1387+ error,
1388+ stackTrace,
1389+ ),
1390+ );
13871391 break ;
13881392 default :
13891393 break ;
@@ -1402,12 +1406,13 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
14021406 ConsoleAPIEvent event,
14031407 ) async {
14041408 final logObject = event.params? ['args' ][1 ] as Map ? ;
1405- final logParams = < String , RemoteObject > {};
1406- for (dynamic obj in logObject? ['preview' ]? ['properties' ] ?? {}) {
1407- if (obj['name' ] != null && obj is Map <String , dynamic >) {
1408- logParams[obj['name' ] as String ] = RemoteObject (obj);
1409- }
1410- }
1409+ final objectId = logObject? ['objectId' ];
1410+ // Always attempt to fetch the full properties instead of relying on
1411+ // `RemoteObject.preview` which only has truncated log messages:
1412+ // https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
1413+ final logParams = objectId != null
1414+ ? await _fetchFullLogParams (objectId, logObject: logObject)
1415+ : _fetchAbbreviatedLogParams (logObject);
14111416
14121417 final logRecord = LogRecord (
14131418 message: await _instanceRef (logParams['message' ]),
@@ -1436,6 +1441,37 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
14361441 );
14371442 }
14381443
1444+ Future <Map <String , RemoteObject >> _fetchFullLogParams (
1445+ String objectId, {
1446+ required Map ? logObject,
1447+ }) async {
1448+ final logParams = < String , RemoteObject > {};
1449+ for (final property in await inspector.getProperties (objectId)) {
1450+ final name = property.name;
1451+ final value = property.value;
1452+ if (name != null && value != null ) {
1453+ logParams[name] = value;
1454+ }
1455+ }
1456+
1457+ // If for some reason we don't get the full log params, then return the
1458+ // abbreviated version instead:
1459+ if (logParams.isEmpty) {
1460+ return _fetchAbbreviatedLogParams (logObject);
1461+ }
1462+ return logParams;
1463+ }
1464+
1465+ Map <String , RemoteObject > _fetchAbbreviatedLogParams (Map ? logObject) {
1466+ final logParams = < String , RemoteObject > {};
1467+ for (dynamic property in logObject? ['preview' ]? ['properties' ] ?? []) {
1468+ if (property is Map <String , dynamic > && property['name' ] != null ) {
1469+ logParams[property['name' ] as String ] = RemoteObject (property);
1470+ }
1471+ }
1472+ return logParams;
1473+ }
1474+
14391475 @override
14401476 Future <Timestamp > getVMTimelineMicros () {
14411477 return _rpcNotSupportedFuture ('getVMTimelineMicros' );
0 commit comments