Unverified Commit 5b1aa60a authored by Kenzie Schmoll's avatar Kenzie Schmoll Committed by GitHub

Enable structured errors by default. (#72446)

* Enable structured errors by default.
parent fa86fb75
......@@ -960,7 +960,15 @@ mixin WidgetInspectorService {
/// Structured errors provide semantic information that can be used by IDEs
/// to enhance the display of errors with rich formatting.
bool isStructuredErrorsEnabled() {
return const bool.fromEnvironment('flutter.inspector.structuredErrors');
// This is a debug mode only feature and will default to false for
// profile mode.
bool enabled = false;
assert(() {
// TODO(kenz): add support for structured errors on the web.
enabled = const bool.fromEnvironment('flutter.inspector.structuredErrors', defaultValue: !kIsWeb);
return true;
}());
return enabled;
}
/// Called to register service extensions.
......
......@@ -56,14 +56,14 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
final StructureErrorTestWidgetInspectorService service = StructureErrorTestWidgetInspectorService();
WidgetInspectorService.instance = service;
test('ext.flutter.inspector.structuredErrors still report error to original on error', () async {
test('ext.flutter.inspector.structuredErrors reports error to _structuredExceptionHandler on error', () async {
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
late FlutterErrorDetails actualError;
bool usingNewHandler = false;
// Creates a spy onError. This spy needs to be set before widgets binding
// initializes.
FlutterError.onError = (FlutterErrorDetails details) {
actualError = details;
usingNewHandler = true;
};
WidgetsFlutterBinding.ensureInitialized();
......@@ -81,8 +81,13 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
);
FlutterError.reportError(expectedError);
// Validates the spy still received an error.
expect(actualError, expectedError);
// For non-web apps, this validates the new handler did not receive an
// error because `FlutterError.onError` was set to
// `WidgetInspectorService._structuredExceptionHandler` when service
// extensions were initialized. For web apps, the new handler should
// have received an error because structured errors are disabled by
// default on the web.
expect(usingNewHandler, equals(kIsWeb));
} finally {
FlutterError.onError = oldHandler;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment