Skip to content

Send text error in JSON and print in tools #58284

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

Merged
merged 18 commits into from
Jun 6, 2020
Merged

Conversation

helin24
Copy link
Member

@helin24 helin24 commented May 30, 2020

Description

This is a follow up to #58118.
Currently, calling flutter run --dart-define=flutter.inspector.structuredErrors=true on the command line will result in errors not being printed because they are captured as structured errors and sent out as JSON. This change lets flutter_tools display the text of errors.

Result if running on phone emulator:

helinx-macbookpro:gallery helinx$ flutter run --dart-define=flutter.inspector.structuredErrors=true
Building flutter tool...
Launching lib/main.dart on iPhone SE (2nd generation) in debug mode...
Running pod install...                                              1.5s
Running Xcode build...

 └─Compiling, linking and signing...                         9.6s
Xcode build done.                                           22.9s
Waiting for iPhone SE (2nd generation) to report its views...          3ms

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following FormatException was thrown building GalleryApp(dirty):
FormatException

The relevant error-causing widget was:
  GalleryApp file:///Users/helinx/Documents/gallery/lib/main.dart:22:16

When the exception was thrown, this was the stack:
#0      GalleryApp.build (package:gallery/main.dart:37:5)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4585:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4511:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4227:5)
#4      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4490:5)
#5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4485:5)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3455:14)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3223:18)
#8      RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1132:16)
#9      RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1103:5)
#10     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1045:17)
#11     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2612:19)
#12     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1044:13)
#13     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:925:7)
#14     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:906:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════
Syncing files to device iPhone SE (2nd generation)...
 3,146ms (!)

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on iPhone SE (2nd generation) is available at: http://127.0.0.1:55386/u1U7kvczBtQ=/

Result if running application on web:

helinx-macbookpro:gallery helinx$ flutter run -d chrome --dart-define=flutter.inspector.structuredErrors=true
Building flutter tool...
Launching lib/main.dart on Chrome in debug mode...
Syncing files to device Chrome...
33,968ms (!)
Debug service listening on ws://127.0.0.1:52335/jW7qQNB-U8w=

Warning: Flutter's support for web development is not stable yet and hasn't
been thoroughly tested in production environments.
For more information see https://flutter.dev/web

🔥  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following FormatException was thrown building GalleryApp(dirty):
FormatException

The relevant error-causing widget was:
  GalleryApp file:///Users/helinx/Documents/gallery/lib/main.dart:22:16

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 214:49  throw_
packages/gallery/main.dart 37:5                                               build
packages/flutter/src/widgets/framework.dart 4585:28                           build
packages/flutter/src/widgets/framework.dart 4511:15                           performRebuild
packages/flutter/src/widgets/framework.dart 4227:5                            rebuild
packages/flutter/src/widgets/framework.dart 4490:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4485:5                            mount
packages/flutter/src/widgets/framework.dart 3455:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3223:18                           updateChild
packages/flutter/src/widgets/binding.dart 1132:16                             [_rebuild]
packages/flutter/src/widgets/binding.dart 1103:5                              mount
packages/flutter/src/widgets/binding.dart 1045:16                             <fn>
packages/flutter/src/widgets/framework.dart 2612:19                           buildScope
packages/flutter/src/widgets/binding.dart 1044:12                             attachToRenderTree
packages/flutter/src/widgets/binding.dart 924:24                              attachRootWidget
packages/flutter/src/widgets/binding.dart 906:7                               <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback

════════════════════════════════════════════════════════════════════════════════════════════════════

Related Issues

None

Tests

I added the following tests:

  • Verify that the start of text is returned from the structured error JSON.
  • Verify that extension stream is listened for
  • Verify that resident_web_runner listens for extension events

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 read the Tree Hygiene wiki page, which explains my responsibilities.
  • 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

Did any tests fail when you ran them? Please read Handling breaking changes.

@fluttergithubbot fluttergithubbot added framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels. labels May 30, 2020
@helin24 helin24 requested review from jonahwilliams and jacob314 May 30, 2020 01:07
@@ -187,6 +190,7 @@ class FlutterDevice {
CompileExpression compileExpression,
ReloadMethod reloadMethod,
GetSkSLMethod getSkSLMethod,
PrintErrorEventMethod printErrorEventMethod,
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be hooked up somewhere to work, are either of the Hot/Cold runners passing this through?

Copy link
Member Author

Choose a reason for hiding this comment

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

They both call connectToServiceProtocol defined on ResidentRunner in their attach methods, so that should mean they use the printErrorEventMethod defined on ResidentRunner too. Are there other places that need to pass in a print method too?

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm_dog2

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with nit

@helin24 helin24 merged commit cce6b3c into flutter:master Jun 6, 2020
@helin24 helin24 deleted the tool-error branch June 6, 2020 02:07
jonahwilliams added a commit that referenced this pull request Jun 6, 2020
jonahwilliams added a commit that referenced this pull request Jun 6, 2020
helin24 added a commit to helin24/flutter that referenced this pull request Jun 8, 2020
helin24 added a commit that referenced this pull request Jun 8, 2020
* Revert "Revert "Send text error in JSON and print in tools (#58284)" (#58872)"

This reverts commit c2d5e18.

* Put streamListen in try/catch if extension events already listened for
zljj0818 pushed a commit to zljj0818/flutter that referenced this pull request Jun 22, 2020
* Revert "Revert "Send text error in JSON and print in tools (flutter#58284)" (flutter#58872)"

This reverts commit c2d5e18.

* Put streamListen in try/catch if extension events already listened for
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
* Send text error in JSON and print in tools

* Add test for error text

* Fix analysis issues

* Move streamListen to try/catch and use global.printStatus

* Extract print error fn and listen for events in web runner

* Add extension listen request to test

* Update packages/flutter_tools/lib/src/resident_runner.dart

Co-authored-by: Jonah Williams <jonahwilliams@google.com>

* Rename error parsing method

* Allow crash if listen for extension stream fails

* Add test for error and non-error extension events

* Fix formatting for TextTreeRenderer

* Use shorter message for second exceptions

* Specify types for map

* Add empty JSON for resident_web_runner test

* Move stream listen to vmservice and add vmservice test

* Fix stream type

* Move structured error log definition to vmservice

* Use correct test matcher isNot

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
* Revert "Revert "Send text error in JSON and print in tools (flutter#58284)" (flutter#58872)"

This reverts commit c2d5e18.

* Put streamListen in try/catch if extension events already listened for
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants