Commit 2618f34d authored by Hixie's avatar Hixie

Improve debugging aids in framework.dart

parent 4561f9eb
...@@ -136,7 +136,16 @@ abstract class GlobalKey extends Key { ...@@ -136,7 +136,16 @@ abstract class GlobalKey extends Key {
static void _notifyListeners() { static void _notifyListeners() {
assert(!_inBuildDirtyComponents); assert(!_inBuildDirtyComponents);
assert(!Widget._notifyingMountStatus); assert(!Widget._notifyingMountStatus);
assert(_debugDuplicates.isEmpty); assert(() {
String message = '';
for (GlobalKey key in _debugDuplicates.keys) {
message += "Duplicate GlobalKey found amongst mounted widgets: $key (${_debugDuplicates[key]} instances)\n";
message += "Most recently registered instance is:\n${_registry[key]}\n";
}
if (!_debugDuplicates.isEmpty)
throw message;
return true;
});
if (_syncedKeys.isEmpty && _removedKeys.isEmpty) if (_syncedKeys.isEmpty && _removedKeys.isEmpty)
return; return;
try { try {
...@@ -535,9 +544,13 @@ abstract class Widget { ...@@ -535,9 +544,13 @@ abstract class Widget {
details.add('hashCode=$hashCode'); details.add('hashCode=$hashCode');
details.add(mounted ? 'mounted' : 'not mounted'); details.add(mounted ? 'mounted' : 'not mounted');
if (_generation != _currentGeneration) { if (_generation != _currentGeneration) {
int delta = _generation - _currentGeneration; if (_generation == 0) {
String sign = delta < 0 ? '' : '+'; details.add('never synced');
details.add('gen$sign$delta'); } else {
int delta = _generation - _currentGeneration;
String sign = delta < 0 ? '' : '+';
details.add('gen$sign$delta');
}
} }
} }
...@@ -885,6 +898,8 @@ abstract class StatefulComponent extends Component { ...@@ -885,6 +898,8 @@ abstract class StatefulComponent extends Component {
void _sync(StatefulComponent old, dynamic slot) { void _sync(StatefulComponent old, dynamic slot) {
if (old == null) { if (old == null) {
if (!_isStateInitialized) { if (!_isStateInitialized) {
assert(mounted);
assert(!_wasMounted);
initState(); initState();
_isStateInitialized = true; _isStateInitialized = true;
} }
...@@ -1008,8 +1023,13 @@ void _buildDirtyComponents() { ...@@ -1008,8 +1023,13 @@ void _buildDirtyComponents() {
// TODO(ianh): Move this to Widget // TODO(ianh): Move this to Widget
void _endSyncPhase() { void _endSyncPhase() {
Widget._currentGeneration += 1; try {
Widget._notifyMountStatusChanged(); Widget._currentGeneration += 1;
Widget._notifyMountStatusChanged();
} catch (e, stack) {
_debugReportException('sending post-sync notifications', e, stack);
return null;
}
} }
// TODO(ianh): Move this to Component // TODO(ianh): Move this to Component
...@@ -1418,7 +1438,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { ...@@ -1418,7 +1438,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper {
continue; // when these nodes are reordered, we just reassign the data continue; // when these nodes are reordered, we just reassign the data
if (!idSet.add(child.key)) { if (!idSet.add(child.key)) {
throw '''If multiple keyed nodes exist as children of another node, they must have unique keys. $this has duplicate child key "${child.key}".'''; throw '''If multiple keyed nodes exist as children of another node, they must have unique keys. ${toStringName()} has multiple children with key "${child.key}".''';
} }
} }
return false; return false;
...@@ -1609,7 +1629,7 @@ class ErrorWidget extends LeafRenderObjectWrapper { ...@@ -1609,7 +1629,7 @@ class ErrorWidget extends LeafRenderObjectWrapper {
void _debugReportException(String context, dynamic exception, StackTrace stack) { void _debugReportException(String context, dynamic exception, StackTrace stack) {
print('------------------------------------------------------------------------'); print('------------------------------------------------------------------------');
print('Exception caught while $context'); 'Exception caught while $context'.split('\n').forEach(print);
print('$exception'); print('$exception');
print('Stack trace:'); print('Stack trace:');
'$stack'.split('\n').forEach(print); '$stack'.split('\n').forEach(print);
......
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