Skip to content

Conversation

@jacob314
Copy link
Contributor

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.
screen shot 2019-01-22 at 7 51 08 pm
screen shot 2019-01-21 at 9 09 01 pm

@jacob314 jacob314 requested review from InMatrix and pq January 28, 2019 22:07
@jacob314
Copy link
Contributor Author

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.

Copy link
Contributor

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?)

Copy link
Contributor

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?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Update or remove?

Copy link
Contributor Author

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.

Copy link
Contributor

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;

?

Copy link
Contributor Author

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.

@jacob314
Copy link
Contributor Author

Please do not review diagnostics.dart or widget_inspector.dart.
Those changes are implementation details that have some rough edges that I will polish before sending out for further review.
The key parts to review in assertions.dart, box.dart,
and FlutterErrorBuilder, RenderErrorBuilder, and WidgetErrorBuilder.
The rest of the CL is mostly just applying the new FlutterErrorBuilder classes to all the existing errors to ensure that they generalize adequately to address all the cases. Those changes can be landed either all at once or incrementally.

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.
All tests do pass but before landing it will likely make sense to add a few more golden tests to improve the code coverage for the error generation logic.

@jacob314 jacob314 force-pushed the structured_error branch 2 times, most recently from 3fa689a to 696c686 Compare January 29, 2019 02:59
Copy link
Contributor Author

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.

@jacob314
Copy link
Contributor Author

Fyi I've layered this as two commits.
696c686
is the much smaller commits with just the critical core changes and the other commit contains using the methods from the core changes to the rest of the code base. Please start by reviewing the core change with the exception of diagnostics.dart which I'm still cleaning up.

@zoechi zoechi added c: contributor-productivity Team-specific productivity, code health, technical debt. framework flutter/packages/flutter repository. See also f: labels. labels Jan 29, 2019
static DiagnosticsNode _createStackFrame(String frame) {
return DiagnosticsNode.message(frame, allowWrap: false);
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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.

@Hixie
Copy link
Contributor

Hixie commented Jan 30, 2019

(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 flutter tool can detect).

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
Notably, this involves filing an issue first and discussing proposals with the community (that is, anyone who is interested but in particular including myself and @goderbauer for this kind of change) before writing code. That way we can make sure to all get on the same page before we write code.

@jacob314 jacob314 closed this Feb 6, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants