-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Refactor to make FlutterError and FlutterErrorDetails return structured data using the existing DiagnosticsNode concepts. #27202
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
Conversation
|
All unit tests pass locally. There are still some lint errors in the inspector and diagnostics.dart files that still need a bit more cleanup. Fundamentally, the core questions to address are whether the FlutterErrrorBuilder abstraction is usable and clear enough and what polish we want to apply to it before landing. |
a173445 to
c2fbf3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lose the braces? (I think that's the preferred style?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix this or elaborate in the comment (and make a TODO?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update or remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this case. @InMatrix this an interesting edge case. We could consider adding some variation of describeChildren to RenderErrorBuilder instead of writing this case directly. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
bool _isDeepStyle(DiagnosticsTreeStyle style) => false;?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. fyi this code needs to be audited before a real review.
c2fbf3b to
e7d5a05
Compare
|
Please do not review diagnostics.dart or widget_inspector.dart. This change is supposed to be non-breaking and I've jumped through hoops in a few places to make that happen. If I've missed something and added breaking logic let me know and I'll cleanup. |
3fa689a to
696c686
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hixie Any thoughts on whether the divergence between this method and the output that is dumped to the console is useful or not? I've matched the display of the old method but I'm lacking the context to understand whether these differences are useful or historic.
|
Fyi I've layered this as two commits. |
696c686 to
b4a3622
Compare
| static DiagnosticsNode _createStackFrame(String frame) { | ||
| return DiagnosticsNode.message(frame, allowWrap: false); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider how this might be merged with #4021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good first step towards 4021 as it centralizes uses os stack trace significantly towards just DiagnosticsStackTrace. I'm happy to merge the relevant parts of the stack_trace library as part of this cl or a follow up cl to finish up the cleanup. Just let me know which you would prefer.
|
(Jacob and I talked about this in person; I'm putting this here for the record.) I think the problem we are solving here is real and I think it's fantastic that we are solving this. I agree with the use cases 100%. I think we should attempt to find a solution that has a much lighter API. My fear is that engineers (that is to say, we) in general already find writing error messages to be highly aversive, and anything we do to raise the barrier to writing error messages would only make things worse. Ideally making objects in a string inspectable would require zero overhead from the perspective of framework developers. For example, one could imagine changing Object.toString or Diagnosticable.toString to encode information in the output (which normally gets stripped out but which IDEs and maybe the As a side note, for future refactors of this size (or indeed any API change) I recommend following our process as described here: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview |
The key new classes added are:
FlutterErrorBuilder, RenderErrorBuilder, and WidgetErrorBuilder which are used to make it simpler
to generate beautiful errors than if the standard DiagnosticsProperty constructors were used directly.
Changes to widget_inspector.dart and diagnostics.dart are not ready for a full review as that code can be cleaned up and the diagnostics.dart code mainly just contains implementation details for the text rendering..
Additional styles and levels of DiagnosticsNodes have been added so this change exactly matches the existing rendering of errors for all cases I'm aware of. If is possible some of these styles should be removed for cases where the existing UI diverged in ways that were not useful but generally my goal is to exactly match the existing output and then worry about beautifying the output in follow on CLs.
The motivation for this CL is to generate beautiful interactive structured versions of flutter errors when rendering error messages in Intellij and the upcoming devtools web app.


Here are screenshots from the devtools web app showing how these structured error objects let us explain flutter errors better.