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,49 +1550,51 @@ abstract class DiagnosticsNode { ...@@ -1536,49 +1550,51 @@ 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; result = <String, Object>{
return <String, Object>{ 'description': toDescription(),
'description': toDescription(), 'type': runtimeType.toString(),
'type': runtimeType.toString(), if (name != null)
if (name != null) 'name': name,
'name': name, if (!showSeparator)
if (!showSeparator) 'showSeparator': showSeparator,
'showSeparator': showSeparator, if (level != DiagnosticLevel.info)
if (level != DiagnosticLevel.info) 'level': describeEnum(level),
'level': describeEnum(level), if (showName == false)
if (showName == false) 'showName': showName,
'showName': showName, if (emptyBodyDescription != null)
if (emptyBodyDescription != null) 'emptyBodyDescription': emptyBodyDescription,
'emptyBodyDescription': emptyBodyDescription, if (style != DiagnosticsTreeStyle.sparse)
if (style != DiagnosticsTreeStyle.sparse) 'style': describeEnum(style),
'style': describeEnum(style), if (allowTruncate)
if (allowTruncate) 'allowTruncate': allowTruncate,
'allowTruncate': allowTruncate, if (hasChildren)
if (hasChildren) 'hasChildren': hasChildren,
'hasChildren': hasChildren, if (linePrefix?.isNotEmpty == true)
if (linePrefix?.isNotEmpty == true) 'linePrefix': linePrefix,
'linePrefix': linePrefix, if (!allowWrap)
if (!allowWrap) 'allowWrap': allowWrap,
'allowWrap': allowWrap, if (allowNameWrap)
if (allowNameWrap) 'allowNameWrap': allowNameWrap,
'allowNameWrap': allowNameWrap, ...delegate.additionalNodeProperties(this),
...delegate.additionalNodeProperties(this), if (delegate.includeProperties)
if (delegate.includeProperties) 'properties': toJsonList(
'properties': toJsonList( delegate.filterProperties(getProperties(), this),
delegate.filterProperties(getProperties(), this), this,
this, delegate,
delegate, ),
), if (delegate.subtreeDepth > 0)
if (delegate.subtreeDepth > 0) 'children': toJsonList(
'children': toJsonList( delegate.filterChildren(getChildren(), this),
delegate.filterChildren(getChildren(), this), this,
this, 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,22 +1638,28 @@ abstract class DiagnosticsNode { ...@@ -1622,22 +1638,28 @@ 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);
assert(description != null); } else {
final String description = toDescription(
if (name == null || name.isEmpty || !showName) parentConfiguration: parentConfiguration);
return description; assert(description != null);
return description.contains('\n') ? '$name$_separator\n$description' if (name == null || name.isEmpty || !showName) {
: '$name$_separator $description'; result = description;
} else {
result = description.contains('\n') ? '$name$_separator\n$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
...@@ -1699,19 +1721,21 @@ abstract class DiagnosticsNode { ...@@ -1699,19 +1721,21 @@ 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, ).render(
).render( this,
this, prefixLineOne: prefixLineOne,
prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines,
prefixOtherLines: prefixOtherLines, parentConfiguration: parentConfiguration,
parentConfiguration: parentConfiguration, );
); return true;
}());
return result;
} }
} }
...@@ -2893,13 +2917,18 @@ class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode { ...@@ -2893,13 +2917,18 @@ 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;
if (_cachedBuilder == null) { } else {
_cachedBuilder = DiagnosticPropertiesBuilder(); assert(() {
value?.debugFillProperties(_cachedBuilder); if (_cachedBuilder == null) {
_cachedBuilder = DiagnosticPropertiesBuilder();
value?.debugFillProperties(_cachedBuilder);
}
return true;
}());
return _cachedBuilder;
} }
return _cachedBuilder;
} }
@override @override
...@@ -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();
} }
final StringBuffer result = StringBuffer(); String shallowString;
result.write(toString()); assert(() {
result.write(joiner); final StringBuffer result = StringBuffer();
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); result.write(toString());
debugFillProperties(builder); result.write(joiner);
result.write( final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)).join(joiner), debugFillProperties(builder);
); result.write(
return result.toString(); builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel))
.join(joiner),
);
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();
} }
final StringBuffer result = StringBuffer(); String shallowString;
result.write(toStringShort()); assert(() {
result.write(joiner); final StringBuffer result = StringBuffer();
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); result.write(toStringShort());
debugFillProperties(builder); result.write(joiner);
result.write( final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)).join(joiner), debugFillProperties(builder);
); result.write(
return result.toString(); builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel))
.join(joiner),
);
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