Repository: flutter
Issue: Hot reloading when the framework is in a broken state causes the tool to dump an exception
Labels: tool,framework,t: hot reload,a: error message,has reproducible steps,P2,found in release: 3.7,found in release: 3.10,team-framework,triaged-framework

STEPS TO REPRODUCE
1. Run this in a shell:
```bash
flutter create issue125659
cd issue125659
echo "import 'package:flutter/rendering.dart';" > lib/main.dart
echo "import 'package:flutter/widgets.dart';" >> lib/main.dart
echo "class RenderTest extends RenderProxyBox { void performLayout() => throw 'test'; }" >> lib/main.dart
echo "class Test extends SingleChildRenderObjectWidget { RenderTest createRenderObject(BuildContext context) => RenderTest(); }" >> lib/main.dart
echo "void main() => runApp(Column(children: [Test(), Placeholder()]));" >> lib/main.dart
flutter run -d linux
```
2. Press "r" in the console to trigger a hot reload.

EXPECTED RESULTS

A whole bunch of errors in the console, but all of them from the Flutter app.

ACTUAL RESULTS

We print "Reassembling main.dart$main-2326759299642447 failed: ext.flutter.reassemble: (-32000) Server error" followed by a stack trace from the tool itself during the hot reload:

```
Creating project issue125659...
Resolving dependencies in issue125659... 
Got dependencies in issue125659.
Wrote 129 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd issue125659
  $ flutter run

Your application code is in issue125659/lib/main.dart.

Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           

(issue125659:8389): dbind-WARNING **: 16:55:52.551: AT-SPI: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following message was thrown during performLayout():
test

The relevant error-causing widget was:
  Test Test:file:///home/ianh/dev/issue125659/lib/main.dart:5:41

When the exception was thrown, this was the stack:
#0      RenderTest.performLayout (package:issue125659/main.dart:3:67)
#1      RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#2      RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#3      ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:52:11)
#4      RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:808:43)
#5      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:903:32)
#6      RenderObject.layout (package:flutter/src/rendering/object.dart:2395:7)
#7      RenderBox.layout (package:flutter/src/rendering/box.dart:2386:11)
#8      RenderView.performLayout (package:flutter/src/rendering/view.dart:173:14)
#9      RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2234:7)
#10     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1016:18)
#11     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:492:19)
#12     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:918:13)
#13     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:358:5)
#14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#15     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1219:9)
#16     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:944:7)
#20     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 3 frames from class _Timer and dart:async-patch)

The following RenderObject was being processed when the exception was fired: RenderTest#3cb3e relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT:
  creator: Test ← Column ← MediaQuery ← _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey
    FlutterView#f387e] ← [root]
  parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
  constraints: BoxConstraints(0.0<=w<=1904.0, 0.0<=h<=Infinity)
  size: MISSING
This RenderObject has no descendants.
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: RenderBox was not laid out: RenderTest#3cb3e relayoutBoundary=up1 NEEDS-PAINT
Another exception was thrown: Updated layout information required for RenderLimitedBox#2ebd4 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.
Another exception was thrown: 'package:flutter/src/widgets/binding.dart': Failed assertion: line 891 pos 14: '!_firstFrameCompleter.isCompleted':
is not true.
Syncing files to device Linux...                                    82ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Linux is available at: http://127.0.0.1:35659/tAcp7VJswgo=/
The Flutter DevTools debugger and profiler on Linux is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:35659/tAcp7VJswgo=/


══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a service extension callback for "ext.flutter.reassemble":
Build scheduled during frame.
While the widget tree was being built, laid out, and painted, a new frame was scheduled to rebuild
the widget tree.
This might be because setState() was called from a layout or paint callback. If a change is needed
to the widget tree, it should be applied as the tree is being built. Scheduling a change for the
subsequent frame instead results in an interface that lags behind by one frame. If this was done to
make your build dependent on a size measured at layout time, consider using a LayoutBuilder,
CustomSingleChildLayout, or CustomMultiChildLayout. If, on the other hand, the one frame delay is
the desired effect, for example because this is an animation, consider scheduling the frame in a
post-frame callback using SchedulerBinding.addPostFrameCallback or using an AnimationController to
trigger the animation.

When the exception was thrown, this was the stack:
#0      WidgetsBinding._handleBuildScheduled.<anonymous closure> (package:flutter/src/widgets/binding.dart:781:9)
#1      WidgetsBinding._handleBuildScheduled (package:flutter/src/widgets/binding.dart:804:6)
#2      BuildOwner.scheduleBuildFor (package:flutter/src/widgets/framework.dart:2606:24)
#3      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4668:12)
#4      Element.reassemble (package:flutter/src/widgets/framework.dart:3429:7)
#5      BuildOwner.reassemble (package:flutter/src/widgets/framework.dart:3162:12)
#6      WidgetsBinding.performReassemble (package:flutter/src/widgets/binding.dart:1021:19)
#7      BindingBase.lockEvents (package:flutter/src/foundation/binding.dart:652:41)
#8      BindingBase.reassembleApplication (package:flutter/src/foundation/binding.dart:700:12)
#9      BindingBase.registerSignalServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:735:23)
#10     BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:945:32)
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════════════════════════

Reassembling main.dart$main-2326759299642447 failed: ext.flutter.reassemble: (-32000) Server error
{"exception":"Build scheduled during frame.\nWhile the widget tree was being built, laid out, and painted, a new frame was scheduled to rebuild
the widget tree.\nThis might be because setState() was called from a layout or paint callback. If a change is needed to the widget tree, it should
be applied as the tree is being built. Scheduling a change for the subsequent frame instead results in an interface that lags behind by one frame.
If this was done to make your build dependent on a size measured at layout time, consider using a LayoutBuilder, CustomSingleChildLayout, or
CustomMultiChildLayout. If, on the other hand, the one frame delay is the desired effect, for example because this is an animation, consider
scheduling the frame in a post-frame callback using SchedulerBinding.addPostFrameCallback or using an AnimationController to trigger the
animation.","stack":"#0      WidgetsBinding._handleBuildScheduled.<anonymous closure> (package:flutter/src/widgets/binding.dart:781:9)\n#1
WidgetsBinding._handleBuildScheduled (package:flutter/src/widgets/binding.dart:804:6)\n#2      BuildOwner.scheduleBuildFor
(package:flutter/src/widgets/framework.dart:2606:24)\n#3      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4668:12)\n#4
Element.reassemble (package:flutter/src/widgets/framework.dart:3429:7)\n#5      BuildOwner.reassemble
(package:flutter/src/widgets/framework.dart:3162:12)\n#6      WidgetsBinding.performReassemble
(package:flutter/src/widgets/binding.dart:1021:19)\n#7      BindingBase.lockEvents (package:flutter/src/foundation/binding.dart:652:41)\n#8
BindingBase.reassembleApplication (package:flutter/src/foundation/binding.dart:700:12)\n#9
BindingBase.registerSignalServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:735:23)\n#10
BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:945:32)\n<asynchronous
suspension>\n","method":"ext.flutter.reassemble"}
#0      new _OutstandingRequest (package:vm_service/src/vm_service.dart:1822:45)
#1      VmService._call (package:vm_service/src/vm_service.dart:2366:21)
#2      VmService.callServiceExtension (package:vm_service/src/vm_service.dart:2337:14)
#3      FlutterVmService._checkedCallServiceExtension (package:flutter_tools/src/vmservice.dart:909:28)
#4      FlutterVmService.invokeFlutterExtensionRpcRaw (package:flutter_tools/src/vmservice.dart:928:49)
#5      FlutterVmService.flutterReassemble (package:flutter_tools/src/vmservice.dart:756:12)
#6      _defaultReassembleHelper (package:flutter_tools/src/run_hot.dart:1321:46)
<asynchronous suspension>
#7      HotRunner._reloadSources (package:flutter_tools/src/run_hot.dart:964:47)
<asynchronous suspension>
#8      HotRunner._hotReloadHelper (package:flutter_tools/src/run_hot.dart:848:16)
<asynchronous suspension>
#9      HotRunner.restart (package:flutter_tools/src/run_hot.dart:743:36)
<asynchronous suspension>
#10     TerminalHandler._commonTerminalInputHandler (package:flutter_tools/src/resident_runner.dart:1768:40)
<asynchronous suspension>
#11     TerminalHandler.processTerminalInput (package:flutter_tools/src/resident_runner.dart:1821:7)
<asynchronous suspension>


Performing hot reload...                                                
Try again after fixing the above error(s).

```

We should certainly not dump that last error (the one with `VmService` in the stack) to the console. We should probably say something along the lines of "the framework seems to be in a broken state; consider a hot restart (R)".