Avoid using FlutterError.fromParts when possible (#43696)
This PR is a follow up of https://github.com/flutter/flutter/pull/42640 Some changes of that PR includes redundant changes using FlutterError.fromParts constructor even though it's not necessary. Some minor changes are: - Remove one unnecessary todo - Fix indent consistencies
This commit is contained in:
committed by
GitHub
parent
d030296a97
commit
aad941e3fa
@@ -439,14 +439,12 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
|
||||
final double transformedValue = activeCurve.transform(t);
|
||||
final double roundedTransformedValue = transformedValue.round().toDouble();
|
||||
if (roundedTransformedValue != t) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Invalid curve endpoint at $t.'),
|
||||
ErrorDescription(
|
||||
'Curves must map 0.0 to near zero and 1.0 to near one but '
|
||||
'${activeCurve.runtimeType} mapped $t to $transformedValue, which '
|
||||
'is near $roundedTransformedValue.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'Invalid curve endpoint at $t.\n'
|
||||
'Curves must map 0.0 to near zero and 1.0 to near one but '
|
||||
'${activeCurve.runtimeType} mapped $t to $transformedValue, which '
|
||||
'is near $roundedTransformedValue.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -192,33 +192,29 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
|
||||
Route<dynamic> _onUnknownRoute(RouteSettings settings) {
|
||||
assert(() {
|
||||
if (widget.onUnknownRoute == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Could not find a generator for route $settings in the $runtimeType.'),
|
||||
ErrorDescription(
|
||||
'Generators for routes are searched for in the following order:\n'
|
||||
' 1. For the "/" route, the "builder" property, if non-null, is used.\n'
|
||||
' 2. Otherwise, the "routes" table is used, if it has an entry for '
|
||||
'the route.\n'
|
||||
' 3. Otherwise, onGenerateRoute is called. It should return a '
|
||||
'non-null value for any valid route not handled by "builder" and "routes".\n'
|
||||
' 4. Finally if all else fails onUnknownRoute is called.\n'
|
||||
'Unfortunately, onUnknownRoute was not set.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'Could not find a generator for route $settings in the $runtimeType.\n'
|
||||
'Generators for routes are searched for in the following order:\n'
|
||||
' 1. For the "/" route, the "builder" property, if non-null, is used.\n'
|
||||
' 2. Otherwise, the "routes" table is used, if it has an entry for '
|
||||
'the route.\n'
|
||||
' 3. Otherwise, onGenerateRoute is called. It should return a '
|
||||
'non-null value for any valid route not handled by "builder" and "routes".\n'
|
||||
' 4. Finally if all else fails onUnknownRoute is called.\n'
|
||||
'Unfortunately, onUnknownRoute was not set.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
final Route<dynamic> result = widget.onUnknownRoute(settings);
|
||||
assert(() {
|
||||
if (result == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The onUnknownRoute callback returned null.'),
|
||||
ErrorDescription(
|
||||
'When the $runtimeType requested the route $settings from its '
|
||||
'onUnknownRoute callback, the callback returned null. Such callbacks '
|
||||
'must never return null.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The onUnknownRoute callback returned null.\n'
|
||||
'When the $runtimeType requested the route $settings from its '
|
||||
'onUnknownRoute callback, the callback returned null. Such callbacks '
|
||||
'must never return null.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -102,10 +102,10 @@ class ChangeNotifier implements Listenable {
|
||||
bool _debugAssertNotDisposed() {
|
||||
assert(() {
|
||||
if (_listeners == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('A $runtimeType was used after being disposed.'),
|
||||
ErrorDescription('Once you have called dispose() on a $runtimeType, it can no longer be used.')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'A $runtimeType was used after being disposed.\n'
|
||||
'Once you have called dispose() on a $runtimeType, it can no longer be used.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -82,10 +82,10 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
||||
final Widget result = builder(context);
|
||||
assert(() {
|
||||
if (result == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The builder for route "${settings.name}" returned null.'),
|
||||
ErrorDescription('Route builders must never return null.')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The builder for route "${settings.name}" returned null.\n'
|
||||
'Route builders must never return null.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -142,16 +142,16 @@ abstract class MultiChildLayoutDelegate {
|
||||
final RenderBox child = _idToChild[childId];
|
||||
assert(() {
|
||||
if (child == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The $this custom multichild layout delegate tried to lay out a non-existent child.'),
|
||||
ErrorDescription('There is no child with the id "$childId".')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The $this custom multichild layout delegate tried to lay out a non-existent child.\n'
|
||||
'There is no child with the id "$childId".'
|
||||
);
|
||||
}
|
||||
if (!_debugChildrenNeedingLayout.remove(child)) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.'),
|
||||
ErrorDescription('Each child must be laid out exactly once.')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.\n'
|
||||
'Each child must be laid out exactly once.'
|
||||
);
|
||||
}
|
||||
try {
|
||||
assert(constraints.debugAssertIsValid(isAppliedConstraint: true));
|
||||
@@ -182,15 +182,15 @@ abstract class MultiChildLayoutDelegate {
|
||||
final RenderBox child = _idToChild[childId];
|
||||
assert(() {
|
||||
if (child == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The $this custom multichild layout delegate tried to position out a non-existent child:'),
|
||||
ErrorDescription('There is no child with the id "$childId".')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The $this custom multichild layout delegate tried to position out a non-existent child:\n'
|
||||
'There is no child with the id "$childId".'
|
||||
);
|
||||
}
|
||||
if (offset == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The $this custom multichild layout delegate provided a null position for the child with id "$childId".')
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The $this custom multichild layout delegate provided a null position for the child with id "$childId".'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -318,13 +318,11 @@ class RenderFlow extends RenderBox
|
||||
final FlowParentData childParentData = child.parentData as FlowParentData;
|
||||
assert(() {
|
||||
if (childParentData._transform != null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Cannot call paintChild twice for the same child.'),
|
||||
ErrorDescription(
|
||||
'The flow delegate of type ${_delegate.runtimeType} attempted to '
|
||||
'paint child $i multiple times, which is not permitted.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'Cannot call paintChild twice for the same child.\n'
|
||||
'The flow delegate of type ${_delegate.runtimeType} attempted to '
|
||||
'paint child $i multiple times, which is not permitted.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -461,15 +461,13 @@ class RenderAspectRatio extends RenderProxyBox {
|
||||
assert(constraints.debugAssertIsValid());
|
||||
assert(() {
|
||||
if (!constraints.hasBoundedWidth && !constraints.hasBoundedHeight) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('$runtimeType has unbounded constraints.'),
|
||||
ErrorDescription(
|
||||
'This $runtimeType was given an aspect ratio of $aspectRatio but was given '
|
||||
'both unbounded width and unbounded height constraints. Because both '
|
||||
"constraints were unbounded, this render object doesn't know how much "
|
||||
'size to consume.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'$runtimeType has unbounded constraints.\n'
|
||||
'This $runtimeType was given an aspect ratio of $aspectRatio but was given '
|
||||
'both unbounded width and unbounded height constraints. Because both '
|
||||
'constraints were unbounded, this render object doesn\'t know how much '
|
||||
'size to consume.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -1018,14 +1018,12 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
|
||||
final Route<dynamic> result = widget.onUnknownRoute(settings);
|
||||
assert(() {
|
||||
if (result == null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('The onUnknownRoute callback returned null.'),
|
||||
ErrorDescription(
|
||||
'When the $runtimeType requested the route $settings from its '
|
||||
'onUnknownRoute callback, the callback returned null. Such callbacks '
|
||||
'must never return null.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'The onUnknownRoute callback returned null.\n'
|
||||
'When the $runtimeType requested the route $settings from its '
|
||||
'onUnknownRoute callback, the callback returned null. Such callbacks '
|
||||
'must never return null.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -136,13 +136,11 @@ bool debugChildrenHaveDuplicateKeys(Widget parent, Iterable<Widget> children) {
|
||||
assert(() {
|
||||
final Key nonUniqueKey = _firstNonUniqueKey(children);
|
||||
if (nonUniqueKey != null) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Duplicate keys found.'),
|
||||
ErrorDescription(
|
||||
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
|
||||
'$parent has multiple children with key $nonUniqueKey.'
|
||||
),
|
||||
]);
|
||||
throw FlutterError(
|
||||
'Duplicate keys found.\n'
|
||||
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
|
||||
'$parent has multiple children with key $nonUniqueKey.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
@@ -165,9 +163,7 @@ bool debugItemsHaveDuplicateKeys(Iterable<Widget> items) {
|
||||
assert(() {
|
||||
final Key nonUniqueKey = _firstNonUniqueKey(items);
|
||||
if (nonUniqueKey != null)
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Duplicate key found: $nonUniqueKey.'),
|
||||
]);
|
||||
throw FlutterError('Duplicate key found: $nonUniqueKey.');
|
||||
return true;
|
||||
}());
|
||||
return false;
|
||||
@@ -315,7 +311,7 @@ bool debugAssertAllWidgetVarsUnset(String reason) {
|
||||
debugPrintGlobalKeyedWidgetLifecycle ||
|
||||
debugProfileBuildsEnabled ||
|
||||
debugHighlightDeprecatedWidgets) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary(reason)]);
|
||||
throw FlutterError(reason);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -190,7 +190,7 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
|
||||
/// change the controller's [value].
|
||||
set selection(TextSelection newSelection) {
|
||||
if (newSelection.start > text.length || newSelection.end > text.length)
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('invalid text selection: $newSelection')]);
|
||||
throw FlutterError('invalid text selection: $newSelection');
|
||||
value = value.copyWith(selection: newSelection, composing: TextRange.empty);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,13 +242,11 @@ class GestureDetector extends StatelessWidget {
|
||||
}
|
||||
final String recognizer = havePan ? 'pan' : 'scale';
|
||||
if (haveVerticalDrag && haveHorizontalDrag) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Incorrect GestureDetector arguments.'),
|
||||
ErrorDescription(
|
||||
'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer '
|
||||
'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'Incorrect GestureDetector arguments.\n'
|
||||
'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer '
|
||||
'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.'
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -229,14 +229,12 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
|
||||
assert(() {
|
||||
final double delta = newPixels - pixels;
|
||||
if (overscroll.abs() > delta.abs()) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('$runtimeType.applyBoundaryConditions returned invalid overscroll value.'),
|
||||
ErrorDescription(
|
||||
'setPixels() was called to change the scroll offset from $pixels to $newPixels.\n'
|
||||
'That is a delta of $delta units.\n'
|
||||
'$runtimeType.applyBoundaryConditions reported an overscroll of $overscroll units.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'$runtimeType.applyBoundaryConditions returned invalid overscroll value.\n'
|
||||
'setPixels() was called to change the scroll offset from $pixels to $newPixels.\n'
|
||||
'That is a delta of $delta units.\n'
|
||||
'$runtimeType.applyBoundaryConditions reported an overscroll of $overscroll units.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
@@ -402,18 +400,16 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
|
||||
assert(() {
|
||||
final double delta = value - pixels;
|
||||
if (result.abs() > delta.abs()) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('${physics.runtimeType}.applyBoundaryConditions returned invalid overscroll value.'),
|
||||
ErrorDescription(
|
||||
'The method was called to consider a change from $pixels to $value, which is a '
|
||||
'delta of ${delta.toStringAsFixed(1)} units. However, it returned an overscroll of '
|
||||
'${result.toStringAsFixed(1)} units, which has a greater magnitude than the delta. '
|
||||
'The applyBoundaryConditions method is only supposed to reduce the possible range '
|
||||
'of movement, not increase it.\n'
|
||||
'The scroll extents are $minScrollExtent .. $maxScrollExtent, and the '
|
||||
'viewport dimension is $viewportDimension.'
|
||||
)
|
||||
]);
|
||||
throw FlutterError(
|
||||
'${physics.runtimeType}.applyBoundaryConditions returned invalid overscroll value.\n'
|
||||
'The method was called to consider a change from $pixels to $value, which is a '
|
||||
'delta of ${delta.toStringAsFixed(1)} units. However, it returned an overscroll of '
|
||||
'${result.toStringAsFixed(1)} units, which has a greater magnitude than the delta. '
|
||||
'The applyBoundaryConditions method is only supposed to reduce the possible range '
|
||||
'of movement, not increase it.\n'
|
||||
'The scroll extents are $minScrollExtent .. $maxScrollExtent, and the '
|
||||
'viewport dimension is $viewportDimension.'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
@@ -780,8 +780,6 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
void _verifySemanticsHandlesWereDisposed() {
|
||||
assert(_lastRecordedSemanticsHandles != null);
|
||||
if (binding.pipelineOwner.debugOutstandingSemanticsHandles > _lastRecordedSemanticsHandles) {
|
||||
// TODO(jacobr): The hint for this one causes a change in line breaks but
|
||||
// I think it is for the best.
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('A SemanticsHandle was active at the end of the test.'),
|
||||
ErrorDescription(
|
||||
|
||||
Reference in New Issue
Block a user