Issue 1:
Steps to Reproduce

Modify any ext.flutter. service extension to throw an exception

For example modify the debugPaint service extension as follows:

registerBoolServiceExtension(
name: 'debugPaint',
getter: () async => debugPaintSizeEnabled,
setter: (bool value) {
throw Exception("Throwing an exception here shouldn't crash"); // new line.
if (debugPaintSizeEnabled == value)
return new Future<Null>.value();
debugPaintSizeEnabled = value;
return _forceRepaint();
}
);

Trigger the service extension either from flutter tool or from intellij.

From flutter tool, press 'p' to trigger this extension.

From intellij you just get a crash in C++ code. With flutter tool you get a bit more information.

Example

flutter (20275): service extension method received: ext.flutter.debugPaint({isolateId: isolates/113087773})
I/flutter (20275): Action "Wait for outer event loop" took 0:00:00.003126
I/flutter (20275): service extension method received: ext.flutter.debugPaint({enabled: true, isolateId: isolates/113087773})
I/flutter (20275): Action "Wait for outer event loop" took 0:00:00.000373
I/flutter (20275): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (20275): The following _Exception was thrown during a service extension callback for
I/flutter (20275): "ext.flutter.debugPaint":
I/flutter (20275): Exception: Throwing an exception here shouldn't crash
I/flutter (20275):
I/flutter (20275): When the exception was thrown, this was the stack:
I/flutter (20275): #0 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding.initServiceExtensions.<anonymous closure>.<anonymous closure> (package:flutter/src/rendering/binding.dart:63:11)
I/flutter (20275): #1 BindingBase.registerBoolServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:283:23)
I/flutter (20275): <asynchronous suspension>
I/flutter (20275): #2 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:392:32)
I/flutter (20275): <asynchronous suspension>
I/flutter (20275): #3 _runExtension (dart:developer/runtime/libdeveloper.dart:85:23)
I/flutter (20275): ════════════════════════════════════════════════════════════════════════════════════════════════════
Error -32000 received from application: Server error
JSON-RPC error -32000: Server error
package:json_rpc_2/src/client.dart 110:64 Client.sendRequest
package:json_rpc_2/src/peer.dart 68:15 Peer.sendRequest
package:flutter_tools/src/vmservice.dart 293:13 VMService._sendRequest
package:flutter_tools/src/vmservice.dart 842:12 VM.invokeRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1111:15 Isolate.invokeRpcRaw
package:flutter_tools/src/vmservice.dart 1240:20 Isolate.invokeFlutterExtensionRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1274:21 Isolate._flutterToggle
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1284:72 Isolate.flutterToggleDebugPaintSizeEnabled
package:flutter_tools/src/resident_runner.dart 213:28 FlutterDevice.toggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 532:20 ResidentRunner._debugToggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 714:15 ResidentRunner._commonTerminalInputHandler
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 758:34 ResidentRunner.processTerminalInput
===== asynchronous gap ===========================
dart:async/zone.dart 1134:38 _rootRunUnary
dart:async/zone.dart 1031:19 _CustomZone.runUnary
dart:async/zone.dart 933:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/broadcast_stream_controller.dart 379:20 _SyncBroadcastStreamController._sendData
dart:async/broadcast_stream_controller.dart 254:5 _BroadcastStreamController.add
dart:async/broadcast_stream_controller.dart 480:11 _AsBroadcastStreamController.add
dart:async/zone.dart 1134:38 _rootRunUnary
dart:async/zone.dart 1031:19 _CustomZone.runUnary
dart:async/zone.dart 933:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_transformers.dart 68:11 _SinkTransformerStreamSubscription._add
dart:async/stream_transformers.dart 15:11 _EventSinkWrapper.add
dart:convert/string_conversion.dart 268:11 _StringAdapterSink.add
dart:convert/string_conversion.dart 273:7 _StringAdapterSink.addSlice
dart:convert/string_conversion.dart 348:20 _Utf8ConversionSink.addSlice
dart:convert/ascii.dart 280:17 _ErrorHandlingAsciiDecoderSink.addSlice
dart:convert/ascii.dart 266:5 _ErrorHandlingAsciiDecoderSink.add
dart:convert/chunked_conversion.dart 86:18 _ConverterStreamEventSink.add
dart:async/stream_transformers.dart 120:24 _SinkTransformerStreamSubscription._handleData
dart:async/zone.dart 1134:38 _rootRunUnary
dart:async/zone.dart 1031:19 _CustomZone.runUnary
dart:async/zone.dart 933:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19 _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7 _StreamController._add
dart:async/stream_controller.dart 585:5 _StreamController.add
dart:io/runtime/binsocket_patch.dart 1714:41 _Socket._onData
dart:async/zone.dart 1138:13 _rootRunUnary
dart:async/zone.dart 1031:19 _CustomZone.runUnary
dart:async/zone.dart 933:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19 _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7 _StreamController._add
dart:async/stream_controller.dart 585:5 _StreamController.add
dart:io/runtime/binsocket_patch.dart 1276:33 new _RawSocket.<fn>
dart:io/runtime/binsocket_patch.dart 819:14 _NativeSocket.issueReadEvent.issue
dart:async/schedule_microtask.dart 41:21 _microtaskLoop
dart:async/schedule_microtask.dart 50:5 _startMicrotaskLoop
dart:isolate/runtime/libisolate_patch.dart 113:13 _runPendingImmediateCallback
dart:isolate/runtime/libisolate_patch.dart 166:5 _RawReceivePortImpl._handleMessage

Lost connection to device.

Issue 2:
Problem: nesting 2 or more widgets in the hierarchy that both use PageStorage without identifiers -- e.g. an ExpansionTile, and a Scrollable -- results in widgets reading/writing into/from the same location; this in turn results in an exception, since the value types used by these widgets are different: the ExpansionTile reads/writes a boolean (isExpanded), the ScrollController a double (scrollPosition). If the types were the same, the problem would be even worse, since the code would run with unexpected behavior.

Cause: PageStorage.{read,write}State() has an optional parameter -- the "identifier" -- under which state info that needs to outlive a widget can be stored. If state is written/read without specifying an identifier, the PageStorage uses the PageStorageKey to compute an identifier as a fallback. This results in the same identifier being computed for widgets with a common PageStorageKey ancestor.

Workaround (or intended use?!): a separate PageStorageKey for each of these widgets.

Suggested fix: start using the identifier in PageStorage.{read,write}State()?

Also, in the current implementation, for the state to be properly restored, we are forced to specify a PageStorageKey for these widgets. Shouldn't all this stashing of state be handled transparently inside the widgets (without the need to explicitly give them PageStorageKeys), so that we are free to specify our own keys (e.g. a GlobalKey) when needed?