Enable structured errors by default. (#72446)
* Enable structured errors by default.
This commit is contained in:
parent
fa86fb75ea
commit
5b1aa60a46
@ -960,7 +960,15 @@ mixin WidgetInspectorService {
|
|||||||
/// Structured errors provide semantic information that can be used by IDEs
|
/// Structured errors provide semantic information that can be used by IDEs
|
||||||
/// to enhance the display of errors with rich formatting.
|
/// to enhance the display of errors with rich formatting.
|
||||||
bool isStructuredErrorsEnabled() {
|
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.
|
/// Called to register service extensions.
|
||||||
|
@ -56,14 +56,14 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
|
|||||||
final StructureErrorTestWidgetInspectorService service = StructureErrorTestWidgetInspectorService();
|
final StructureErrorTestWidgetInspectorService service = StructureErrorTestWidgetInspectorService();
|
||||||
WidgetInspectorService.instance = service;
|
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;
|
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
|
||||||
|
|
||||||
late FlutterErrorDetails actualError;
|
bool usingNewHandler = false;
|
||||||
// Creates a spy onError. This spy needs to be set before widgets binding
|
// Creates a spy onError. This spy needs to be set before widgets binding
|
||||||
// initializes.
|
// initializes.
|
||||||
FlutterError.onError = (FlutterErrorDetails details) {
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
actualError = details;
|
usingNewHandler = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@ -81,8 +81,13 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
|
|||||||
);
|
);
|
||||||
FlutterError.reportError(expectedError);
|
FlutterError.reportError(expectedError);
|
||||||
|
|
||||||
// Validates the spy still received an error.
|
// For non-web apps, this validates the new handler did not receive an
|
||||||
expect(actualError, expectedError);
|
// 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 {
|
} finally {
|
||||||
FlutterError.onError = oldHandler;
|
FlutterError.onError = oldHandler;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user