Description
Background:
In flutter/flutter#40191 I'm attempting to add support for the debug extension with a --no-launch
argument.
I've updated the tool so that when we anticipate connecting via the chrome extension, we don't call runMain on the app connection and instead get the debug connection from the extensionDebugConnections
controller.
Once I've opened the page and clicked the extension icon to start debugging, I see everything initially succeed, only to crash with several unhandled exceptions. This seems to be partially triggered by the devtools starting up, which on my machine will also have the debug extension running in its tab.
Original exception:
NoSuchMethodError: NoSuchMethodError: The getter 'length' was called on null.
Receiver: null
Tried calling: length
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 Utf8Encoder.convert (dart:convert/utf.dart:79:31)
#2 Codec.encode (dart:convert/codec.dart:21:32)
#3 ChromeProxyService._chromeConsoleStreamController.<anonymous closure>.<anonymous closure> (package:dwds/src/services/chrome_proxy_service.dart:470:30)
#4 _rootRunUnary (dart:async/zone.dart:1132:38)
#5 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#7 CastStreamSubscription._onData (dart:_internal/async_cast.dart:81:11)
#8 _rootRunUnary (dart:async/zone.dart:1132:38)
#9 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#10 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#11 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#12 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#13 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
#14 _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
#15 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
#16 _rootRunUnary (dart:async/zone.dart:1132:38)
#17 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#19 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#20 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#21 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
#22 _WhereStream._handleData (dart:async/stream_pipe.dart:207:12)
#23 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
#24 _rootRunUnary (dart:async/zone.dart:1132:38)
#25 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#27 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#28 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#29 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
#30 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
#31 _rootRun (dart:async/zone.dart:1120:38)
#32 _CustomZone.run (dart:async/zone.dart:1021:19)
#33 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#34 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#35 _rootRun (dart:async/zone.dart:1124:13)
#36 _CustomZone.run (dart:async/zone.dart:1021:19)
#37 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#38 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#39 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#40 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#41 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#42 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
Patching this locally with a ?? ''
check on the encoding prevents this error, but this results in a new exception:
StateError: Bad state: Cannot add new events after calling close
#0 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:249:24)
#1 ExtensionDebugger.close (package:dwds/src/servers/extension_debugger.dart:107:22)
#2 DebugConnection.close (package:dwds/src/connections/debug_connection.dart:37:57)
<asynchronous suspension>
#3 new DebugConnection.<anonymous closure> (package:dwds/src/connections/debug_connection.dart:22:7)
#4 _rootRunUnary (dart:async/zone.dart:1132:38)
#5 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#6 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#8 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#9 Future._complete (dart:async/future_impl.dart:512:7)
#10 _cancelAndValue (dart:async/stream_pipe.dart:63:12)
#11 Stream.first.<anonymous closure> (dart:async/stream.dart:1249:11)
#12 _rootRunUnary (dart:async/zone.dart:1132:38)
#13 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#14 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#15 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#16 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#17 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
#18 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
#19 _rootRun (dart:async/zone.dart:1120:38)
#20 _CustomZone.run (dart:async/zone.dart:1021:19)
#21 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#22 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#23 _rootRun (dart:async/zone.dart:1124:13)
#24 _CustomZone.run (dart:async/zone.dart:1021:19)
#25 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#26 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#27 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#28 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#29 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#30 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
I don't think either stack trace points to a root cause, since it seems like something else is causing the extension/dwds to get into a bad state. I also tried to disable the devtools launch, but it looks like it is required