Unverified Commit 763f8754 authored by Ferhat's avatar Ferhat Committed by GitHub

Treeshake debugFillProperties (#53303)

parent 64426111
...@@ -119,6 +119,17 @@ mixin AnimationLocalListenersMixin { ...@@ -119,6 +119,17 @@ mixin AnimationLocalListenersMixin {
void notifyListeners() { void notifyListeners() {
final List<VoidCallback> localListeners = List<VoidCallback>.from(_listeners); final List<VoidCallback> localListeners = List<VoidCallback>.from(_listeners);
for (final VoidCallback listener in localListeners) { for (final VoidCallback listener in localListeners) {
InformationCollector collector;
assert(() {
collector = () sync* {
yield DiagnosticsProperty<AnimationLocalListenersMixin>(
'The $runtimeType notifying listeners was',
this,
style: DiagnosticsTreeStyle.errorProperty,
);
};
return true;
}());
try { try {
if (_listeners.contains(listener)) if (_listeners.contains(listener))
listener(); listener();
...@@ -128,13 +139,7 @@ mixin AnimationLocalListenersMixin { ...@@ -128,13 +139,7 @@ mixin AnimationLocalListenersMixin {
stack: stack, stack: stack,
library: 'animation library', library: 'animation library',
context: ErrorDescription('while notifying listeners for $runtimeType'), context: ErrorDescription('while notifying listeners for $runtimeType'),
informationCollector: () sync* { informationCollector: collector,
yield DiagnosticsProperty<AnimationLocalListenersMixin>(
'The $runtimeType notifying listeners was',
this,
style: DiagnosticsTreeStyle.errorProperty,
);
},
)); ));
} }
} }
...@@ -192,18 +197,23 @@ mixin AnimationLocalStatusListenersMixin { ...@@ -192,18 +197,23 @@ mixin AnimationLocalStatusListenersMixin {
if (_statusListeners.contains(listener)) if (_statusListeners.contains(listener))
listener(status); listener(status);
} catch (exception, stack) { } catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails( InformationCollector collector;
exception: exception, assert(() {
stack: stack, collector = () sync* {
library: 'animation library',
context: ErrorDescription('while notifying status listeners for $runtimeType'),
informationCollector: () sync* {
yield DiagnosticsProperty<AnimationLocalStatusListenersMixin>( yield DiagnosticsProperty<AnimationLocalStatusListenersMixin>(
'The $runtimeType notifying status listeners was', 'The $runtimeType notifying status listeners was',
this, this,
style: DiagnosticsTreeStyle.errorProperty, style: DiagnosticsTreeStyle.errorProperty,
); );
}, };
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'animation library',
context: ErrorDescription('while notifying status listeners for $runtimeType'),
informationCollector: collector
)); ));
} }
} }
......
...@@ -1112,7 +1112,21 @@ class TextTreeRenderer { ...@@ -1112,7 +1112,21 @@ class TextTreeRenderer {
}) { }) {
if (kReleaseMode) { if (kReleaseMode) {
return ''; return '';
} else {
return _debugRender(
node,
prefixLineOne: prefixLineOne,
prefixOtherLines: prefixOtherLines,
parentConfiguration: parentConfiguration);
}
} }
String _debugRender(
DiagnosticsNode node, {
String prefixLineOne = '',
String prefixOtherLines,
TextTreeConfiguration parentConfiguration,
}) {
final bool isSingleLine = _isSingleLine(node.style) && parentConfiguration?.lineBreakProperties != true; final bool isSingleLine = _isSingleLine(node.style) && parentConfiguration?.lineBreakProperties != true;
prefixOtherLines ??= prefixLineOne; prefixOtherLines ??= prefixLineOne;
if (node.linePrefix != null) { if (node.linePrefix != null) {
...@@ -1536,11 +1550,10 @@ abstract class DiagnosticsNode { ...@@ -1536,11 +1550,10 @@ abstract class DiagnosticsNode {
/// plugin. /// plugin.
@mustCallSuper @mustCallSuper
Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) { Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) {
if (kReleaseMode) { Map<String, Object> result = <String, Object>{};
return <String, Object>{}; assert(() {
}
final bool hasChildren = getChildren().isNotEmpty; final bool hasChildren = getChildren().isNotEmpty;
return <String, Object>{ result = <String, Object>{
'description': toDescription(), 'description': toDescription(),
'type': runtimeType.toString(), 'type': runtimeType.toString(),
if (name != null) if (name != null)
...@@ -1579,6 +1592,9 @@ abstract class DiagnosticsNode { ...@@ -1579,6 +1592,9 @@ abstract class DiagnosticsNode {
delegate, delegate,
), ),
}; };
return true;
}());
return result;
} }
/// Serializes a [List] of [DiagnosticsNode]s to a JSON list according to /// Serializes a [List] of [DiagnosticsNode]s to a JSON list according to
...@@ -1622,23 +1638,29 @@ abstract class DiagnosticsNode { ...@@ -1622,23 +1638,29 @@ abstract class DiagnosticsNode {
TextTreeConfiguration parentConfiguration, TextTreeConfiguration parentConfiguration,
DiagnosticLevel minLevel = DiagnosticLevel.info, DiagnosticLevel minLevel = DiagnosticLevel.info,
}) { }) {
if (kReleaseMode) { String result = super.toString();
return super.toString();
}
assert(style != null); assert(style != null);
assert(minLevel != null); assert(minLevel != null);
if (_isSingleLine(style)) assert(() {
return toStringDeep(parentConfiguration: parentConfiguration, minLevel: minLevel); if (_isSingleLine(style)) {
result = toStringDeep(
final String description = toDescription(parentConfiguration: parentConfiguration); parentConfiguration: parentConfiguration, minLevel: minLevel);
} else {
final String description = toDescription(
parentConfiguration: parentConfiguration);
assert(description != null); assert(description != null);
if (name == null || name.isEmpty || !showName) if (name == null || name.isEmpty || !showName) {
return description; result = description;
} else {
return description.contains('\n') ? '$name$_separator\n$description' result = description.contains('\n') ? '$name$_separator\n$description'
: '$name$_separator $description'; : '$name$_separator $description';
} }
}
return true;
}());
return result;
}
/// Returns a configuration specifying how this object should be rendered /// Returns a configuration specifying how this object should be rendered
/// as text art. /// as text art.
...@@ -1699,10 +1721,9 @@ abstract class DiagnosticsNode { ...@@ -1699,10 +1721,9 @@ abstract class DiagnosticsNode {
TextTreeConfiguration parentConfiguration, TextTreeConfiguration parentConfiguration,
DiagnosticLevel minLevel = DiagnosticLevel.debug, DiagnosticLevel minLevel = DiagnosticLevel.debug,
}) { }) {
if (kReleaseMode) { String result = '';
return ''; assert(() {
} result = TextTreeRenderer(
return TextTreeRenderer(
minLevel: minLevel, minLevel: minLevel,
wrapWidth: 65, wrapWidth: 65,
wrapWidthProperties: 65, wrapWidthProperties: 65,
...@@ -1712,6 +1733,9 @@ abstract class DiagnosticsNode { ...@@ -1712,6 +1733,9 @@ abstract class DiagnosticsNode {
prefixOtherLines: prefixOtherLines, prefixOtherLines: prefixOtherLines,
parentConfiguration: parentConfiguration, parentConfiguration: parentConfiguration,
); );
return true;
}());
return result;
} }
} }
...@@ -2893,14 +2917,19 @@ class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode { ...@@ -2893,14 +2917,19 @@ class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode {
/// ///
/// It will cache the result to prevent duplicate operation. /// It will cache the result to prevent duplicate operation.
DiagnosticPropertiesBuilder get builder { DiagnosticPropertiesBuilder get builder {
if (kReleaseMode) if (kReleaseMode) {
return null; return null;
} else {
assert(() {
if (_cachedBuilder == null) { if (_cachedBuilder == null) {
_cachedBuilder = DiagnosticPropertiesBuilder(); _cachedBuilder = DiagnosticPropertiesBuilder();
value?.debugFillProperties(_cachedBuilder); value?.debugFillProperties(_cachedBuilder);
} }
return true;
}());
return _cachedBuilder; return _cachedBuilder;
} }
}
@override @override
DiagnosticsTreeStyle get style { DiagnosticsTreeStyle get style {
...@@ -2920,10 +2949,12 @@ class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode { ...@@ -2920,10 +2949,12 @@ class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode {
@override @override
String toDescription({ TextTreeConfiguration parentConfiguration }) { String toDescription({ TextTreeConfiguration parentConfiguration }) {
if (kReleaseMode) { String result = '';
return ''; assert(() {
} result = value.toStringShort();
return value.toStringShort(); return true;
}());
return result;
} }
} }
...@@ -3002,9 +3033,10 @@ class DiagnosticPropertiesBuilder { ...@@ -3002,9 +3033,10 @@ class DiagnosticPropertiesBuilder {
/// Add a property to the list of properties. /// Add a property to the list of properties.
void add(DiagnosticsNode property) { void add(DiagnosticsNode property) {
if (!kReleaseMode) { assert(() {
properties.add(property); properties.add(property);
} return true;
}());
} }
/// List of properties accumulated so far. /// List of properties accumulated so far.
...@@ -3376,15 +3408,21 @@ abstract class DiagnosticableTree with Diagnosticable { ...@@ -3376,15 +3408,21 @@ abstract class DiagnosticableTree with Diagnosticable {
if (kReleaseMode) { if (kReleaseMode) {
return toString(); return toString();
} }
String shallowString;
assert(() {
final StringBuffer result = StringBuffer(); final StringBuffer result = StringBuffer();
result.write(toString()); result.write(toString());
result.write(joiner); result.write(joiner);
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
debugFillProperties(builder); debugFillProperties(builder);
result.write( result.write(
builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)).join(joiner), builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel))
.join(joiner),
); );
return result.toString(); shallowString = result.toString();
return true;
}());
return shallowString;
} }
/// Returns a string representation of this node and its descendants. /// Returns a string representation of this node and its descendants.
...@@ -3463,15 +3501,21 @@ mixin DiagnosticableTreeMixin implements DiagnosticableTree { ...@@ -3463,15 +3501,21 @@ mixin DiagnosticableTreeMixin implements DiagnosticableTree {
if (kReleaseMode) { if (kReleaseMode) {
return toString(); return toString();
} }
String shallowString;
assert(() {
final StringBuffer result = StringBuffer(); final StringBuffer result = StringBuffer();
result.write(toStringShort()); result.write(toStringShort());
result.write(joiner); result.write(joiner);
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
debugFillProperties(builder); debugFillProperties(builder);
result.write( result.write(
builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)).join(joiner), builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel))
.join(joiner),
); );
return result.toString(); shallowString = result.toString();
return true;
}());
return shallowString;
} }
@override @override
......
...@@ -75,6 +75,13 @@ class PointerRouter { ...@@ -75,6 +75,13 @@ class PointerRouter {
event = event.transformed(transform); event = event.transformed(transform);
route(event); route(event);
} catch (exception, stack) { } catch (exception, stack) {
InformationCollector collector;
assert(() {
collector = () sync* {
yield DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
};
return true;
}());
FlutterError.reportError(FlutterErrorDetailsForPointerRouter( FlutterError.reportError(FlutterErrorDetailsForPointerRouter(
exception: exception, exception: exception,
stack: stack, stack: stack,
...@@ -83,9 +90,7 @@ class PointerRouter { ...@@ -83,9 +90,7 @@ class PointerRouter {
router: this, router: this,
route: route, route: route,
event: event, event: event,
informationCollector: () sync* { informationCollector: collector
yield DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
},
)); ));
} }
} }
......
...@@ -55,14 +55,19 @@ class PointerSignalResolver { ...@@ -55,14 +55,19 @@ class PointerSignalResolver {
try { try {
_firstRegisteredCallback(_currentEvent); _firstRegisteredCallback(_currentEvent);
} catch (exception, stack) { } catch (exception, stack) {
InformationCollector collector;
assert(() {
collector = () sync* {
yield DiagnosticsProperty<PointerSignalEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
};
return true;
}());
FlutterError.reportError(FlutterErrorDetails( FlutterError.reportError(FlutterErrorDetails(
exception: exception, exception: exception,
stack: stack, stack: stack,
library: 'gesture library', library: 'gesture library',
context: ErrorDescription('while resolving a PointerSignalEvent'), context: ErrorDescription('while resolving a PointerSignalEvent'),
informationCollector: () sync* { informationCollector: collector
yield DiagnosticsProperty<PointerSignalEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
},
)); ));
} }
_firstRegisteredCallback = null; _firstRegisteredCallback = null;
......
...@@ -181,15 +181,20 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT ...@@ -181,15 +181,20 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
}()); }());
result = callback(); result = callback();
} catch (exception, stack) { } catch (exception, stack) {
InformationCollector collector;
assert(() {
collector = () sync* {
yield StringProperty('Handler', name);
yield DiagnosticsProperty<GestureRecognizer>('Recognizer', this, style: DiagnosticsTreeStyle.errorProperty);
};
return true;
}());
FlutterError.reportError(FlutterErrorDetails( FlutterError.reportError(FlutterErrorDetails(
exception: exception, exception: exception,
stack: stack, stack: stack,
library: 'gesture', library: 'gesture',
context: ErrorDescription('while handling a gesture'), context: ErrorDescription('while handling a gesture'),
informationCollector: () sync* { informationCollector: collector
yield StringProperty('Handler', name);
yield DiagnosticsProperty<GestureRecognizer>('Recognizer', this, style: DiagnosticsTreeStyle.errorProperty);
},
)); ));
} }
return result; return result;
......
...@@ -333,16 +333,21 @@ abstract class ImageProvider<T> { ...@@ -333,16 +333,21 @@ abstract class ImageProvider<T> {
await null; // wait an event turn in case a listener has been added to the image stream. await null; // wait an event turn in case a listener has been added to the image stream.
final _ErrorImageCompleter imageCompleter = _ErrorImageCompleter(); final _ErrorImageCompleter imageCompleter = _ErrorImageCompleter();
stream.setCompleter(imageCompleter); stream.setCompleter(imageCompleter);
InformationCollector collector;
assert(() {
collector = () sync* {
yield DiagnosticsProperty<ImageProvider>('Image provider', this);
yield DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration);
yield DiagnosticsProperty<T>('Image key', key, defaultValue: null);
};
return true;
}());
imageCompleter.setError( imageCompleter.setError(
exception: exception, exception: exception,
stack: stack, stack: stack,
context: ErrorDescription('while resolving an image'), context: ErrorDescription('while resolving an image'),
silent: true, // could be a network error or whatnot silent: true, // could be a network error or whatnot
informationCollector: () sync* { informationCollector: collector
yield DiagnosticsProperty<ImageProvider>('Image provider', this);
yield DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration);
yield DiagnosticsProperty<T>('Image key', key, defaultValue: null);
},
); );
}, },
); );
...@@ -384,13 +389,18 @@ abstract class ImageProvider<T> { ...@@ -384,13 +389,18 @@ abstract class ImageProvider<T> {
if (handleError != null) { if (handleError != null) {
handleError(exception, stack); handleError(exception, stack);
} else { } else {
FlutterError.onError(FlutterErrorDetails( InformationCollector collector;
context: ErrorDescription('while checking the cache location of an image'), assert(() {
informationCollector: () sync* { collector = () sync* {
yield DiagnosticsProperty<ImageProvider>('Image provider', this); yield DiagnosticsProperty<ImageProvider>('Image provider', this);
yield DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration); yield DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration);
yield DiagnosticsProperty<T>('Image key', key, defaultValue: null); yield DiagnosticsProperty<T>('Image key', key, defaultValue: null);
}, };
return true;
}());
FlutterError.onError(FlutterErrorDetails(
context: ErrorDescription('while checking the cache location of an image'),
informationCollector: collector,
exception: exception, exception: exception,
stack: stack, stack: stack,
)); ));
...@@ -626,13 +636,18 @@ abstract class AssetBundleImageProvider extends ImageProvider<AssetBundleImageKe ...@@ -626,13 +636,18 @@ abstract class AssetBundleImageProvider extends ImageProvider<AssetBundleImageKe
/// image using [loadAsync]. /// image using [loadAsync].
@override @override
ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) { ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) {
InformationCollector collector;
assert(() {
collector = () sync* {
yield DiagnosticsProperty<ImageProvider>('Image provider', this);
yield DiagnosticsProperty<AssetBundleImageKey>('Image key', key);
};
return true;
}());
return MultiFrameImageStreamCompleter( return MultiFrameImageStreamCompleter(
codec: _loadAsync(key, decode), codec: _loadAsync(key, decode),
scale: key.scale, scale: key.scale,
informationCollector: () sync* { informationCollector: collector
yield DiagnosticsProperty<ImageProvider>('Image provider', this);
yield DiagnosticsProperty<AssetBundleImageKey>('Image key', key);
},
); );
} }
......
...@@ -254,17 +254,22 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -254,17 +254,22 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
callback(timings); callback(timings);
} }
} catch (exception, stack) { } catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails( InformationCollector collector;
exception: exception, assert(() {
stack: stack, collector = () sync* {
context: ErrorDescription('while executing callbacks for FrameTiming'),
informationCollector: () sync* {
yield DiagnosticsProperty<TimingsCallback>( yield DiagnosticsProperty<TimingsCallback>(
'The TimingsCallback that gets executed was', 'The TimingsCallback that gets executed was',
callback, callback,
style: DiagnosticsTreeStyle.errorProperty, style: DiagnosticsTreeStyle.errorProperty,
); );
}, };
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
context: ErrorDescription('while executing callbacks for FrameTiming'),
informationCollector: collector
)); ));
} }
} }
......
...@@ -1469,18 +1469,23 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier { ...@@ -1469,18 +1469,23 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
listener(_highlightMode); listener(_highlightMode);
} }
} catch (exception, stack) { } catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails( InformationCollector collector;
exception: exception, assert(() {
stack: stack, collector = () sync* {
library: 'widgets library',
context: ErrorDescription('while dispatching notifications for $runtimeType'),
informationCollector: () sync* {
yield DiagnosticsProperty<FocusManager>( yield DiagnosticsProperty<FocusManager>(
'The $runtimeType sending notification was', 'The $runtimeType sending notification was',
this, this,
style: DiagnosticsTreeStyle.errorProperty, style: DiagnosticsTreeStyle.errorProperty,
); );
}, };
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'widgets library',
context: ErrorDescription('while dispatching notifications for $runtimeType'),
informationCollector: collector,
)); ));
} }
} }
......
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