Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more structure to errors. #34684

Merged
merged 2 commits into from Jun 20, 2019
Merged

Conversation

@jacob314
Copy link
Contributor

@jacob314 jacob314 commented Jun 18, 2019

Description

This CL refactors more FlutterError messages to take advantage of structured error functionality.
This is a follow up to #30983

Related Issues

Replace this paragraph with a list of issues related to this PR from our [issue database]. Indicate, which of these issues are resolved or fixed by this PR.

Tests

I added tests for the error messages in multiple packages as existing test coverage was quite spotty.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

@jacob314 jacob314 requested review from goderbauer and pq Jun 18, 2019
pq
pq approved these changes Jun 19, 2019
Copy link
Contributor

@pq pq left a comment

Exciting to see this all come together! 🔥

'Tried to paint a RenderObject reentrantly.\n'
'The following RenderObject was already being painted when it was '
'painted again:\n'
' ${toStringShallow(joiner: "\n ")}\n'
Copy link
Contributor

@pq pq Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see these going away! 👍

throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A GlobalKey was used multiple times inside one widget\'s child list.'),
DiagnosticsProperty<GlobalKey>('The offending GlobalKey was', key),
parent.describeElement('The parent of the widgets with that key was'),
Copy link
Contributor

@pq pq Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need to qualify describeElement with parent here?

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks consistent with the previous error message which was describing the parent. If the parent was removed the error would be describing a describing the widget with the key not its parent.

'The parent of the widgets with that key was:\n  $parent\n'

became

parent.describeElement('The parent of the widgets with that key was'),

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
Copy link
Contributor

@pq pq Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider sorting these imports?

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing that import. Auto-import of unimported libraries gets a bit confused in the flutter sdk.

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks for unused imports also appear to be confused likely by re-exported methods that are used. For example, both material and widget re-export some methods from foundation that are indeed used. Fixing that issue would be a bit subtle.

'example, a RenderSliver cannot be the child of a RenderBox because '
'a RenderSliver does not understand the RenderBox layout protocol.',
),
ErrorDescription(''),
Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ErrorDescription('') look kinda odd...

Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there maybe be a configuration option somewhere to mark paragraphs that should be surrounded by blank lines?

Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or a specific Error DiagnosticsNode class that just represents a blank line?

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree those look bad.
I'm happy to add an DiagnosticSpacer or ErrorSpacer class that is sugar for this.
Let me know if that sounds reasonable.

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other option would be to add a trailing '\n' to the previous ErrorDescription but that makes the intent less obvious to someone reading the message at it would be reasonable to assume that all ErrorDescription objects should just have a trailing \n.

Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the syntactic sugar idea.

Copy link
Contributor Author

@jacob314 jacob314 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added ErrorSpacer, used it everywhere we were creating empty DiagnosticsNode objects as spacer or adhoc adding multiple line breaks at the end of sections in error messages.
Fixed a couple cases where we had accidentally extra unintended whitespace in the process and added tests.

@jacob314
Copy link
Contributor Author

@jacob314 jacob314 commented Jun 19, 2019

Ready for another look. I'm not sure if the existing spacing between blocks in the Semantics error message case was intentional or accidental. Left in line breaks between entries in the list in case they were considered useful. Please comment in semantics_test.dart if they should be removed.

Copy link
Member

@goderbauer goderbauer left a comment

LGTM

@@ -175,6 +175,19 @@ class ErrorHint extends _ErrorDiagnostic {
ErrorHint._fromParts(List<Object> messageParts) : super._fromParts(messageParts, level:DiagnosticLevel.hint);
}

/// An [ErrorSpacer] creates an empty [DiagnosticsNode], that can be used tune
Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there seems to be a word missing? "can be used to tune"?

Copy link
Contributor Author

@jacob314 jacob314 Jun 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

/// An [ErrorSpacer] creates an empty [DiagnosticsNode], that can be used tune
/// the spacing between other [DiagnosticsNode] objects.
class ErrorSpacer extends DiagnosticsProperty<void> {
/// Creates a empty space to insert into a list of [DiagnosticNode] objects
Copy link
Member

@goderbauer goderbauer Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a -> an empty space?

Copy link
Contributor Author

@jacob314 jacob314 Jun 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jacob314 jacob314 force-pushed the structured_error_step_2 branch from a2148cf to c613e28 Jun 20, 2019
@jacob314 jacob314 merged commit 38f8490 into flutter:master Jun 20, 2019
39 checks passed
@jacob314 jacob314 deleted the structured_error_step_2 branch Jun 20, 2019
johnsonmh added a commit to johnsonmh/flutter that referenced this issue Jul 30, 2019
Breaking change to extremely rarely used ParentDataWidget.debugDescribeInvalidAncestorChain api changing the return type of the method from String to DiagnosticsNode.
albertusdev pushed a commit that referenced this issue Oct 28, 2019
* Add structured errors in Animations, TabView, ChangeNotifier

* Add structured error on MaterialPageRoute, BoxBorder, DecorationImagePainter, TextSpan

* Add structured errors in Debug

* Fix test errors

* Add structured errors in Scaffold and Stepper

* Add structured errors in part of Rendering Layer

* Fix failing test due to FloatingPoint precision

* Fix failing tests due to precision error and not using final

* Fix failing test due to floating precision error with RegEx instead

* Add structured error in CustomLayout and increase test coverage

* Add structured error & its test in ListBody

* Add structured error in ProxyBox and increase test coverage

* Add structured error message in Viewport

* Fix styles and add more assertions on ErrorHint and DiagnosticProperty

* Add structured error in scheduler/binding and scheduler/ticker

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in AssetBundle and TextInput

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured errors in several widgets #1

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove unused import

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add assertions on hint messages

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix catch spacing

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in several widgets part 2 and increase code coverage

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in flutter_test/widget_tester

* Fix floating precision accuracy by using RegExp

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove todo to add tests in Scaffold showBottomSheet

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix reviews by indenting lines and fixing the assertion orders

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix failing tests due to renaming class

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Try skipping the NetworkBundleTest

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove leading space in material/debug error hint

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>
Inconnu08 added a commit to Inconnu08/flutter that referenced this issue Nov 26, 2019
…#42640)

* Add structured errors in Animations, TabView, ChangeNotifier

* Add structured error on MaterialPageRoute, BoxBorder, DecorationImagePainter, TextSpan

* Add structured errors in Debug

* Fix test errors

* Add structured errors in Scaffold and Stepper

* Add structured errors in part of Rendering Layer

* Fix failing test due to FloatingPoint precision

* Fix failing tests due to precision error and not using final

* Fix failing test due to floating precision error with RegEx instead

* Add structured error in CustomLayout and increase test coverage

* Add structured error & its test in ListBody

* Add structured error in ProxyBox and increase test coverage

* Add structured error message in Viewport

* Fix styles and add more assertions on ErrorHint and DiagnosticProperty

* Add structured error in scheduler/binding and scheduler/ticker

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in AssetBundle and TextInput

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured errors in several widgets #1

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove unused import

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add assertions on hint messages

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix catch spacing

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in several widgets part 2 and increase code coverage

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Add structured error in flutter_test/widget_tester

* Fix floating precision accuracy by using RegExp

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove todo to add tests in Scaffold showBottomSheet

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix reviews by indenting lines and fixing the assertion orders

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Fix failing tests due to renaming class

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Try skipping the NetworkBundleTest

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>

* Remove leading space in material/debug error hint

Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants