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
|
||||
/// 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user