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 function to set structured error early #58118

Merged
merged 12 commits into from May 28, 2020

Conversation

helin24
Copy link
Member

@helin24 helin24 commented May 27, 2020

Description

We noticed while testing exception logging in flutter-intellij that early exceptions (e.g. we tested throwing an exception immediately in the build method of GalleryApp) aren't handled by the structured handler. This change adds an option for a project to use the structured handler immediately instead of waiting for it to be registered later.

Run output before change:

Running "flutter pub get" in gallery...                             0.7s
Launching lib/main.dart on iPhone SE (2nd generation) in debug mode...
Running pod install...                                              2.4s
Running Xcode build...
Xcode build done.                                           53.2s
Debug service listening on ws://127.0.0.1:52394/VOAW1GUS21Y=/ws
Syncing files to device iPhone SE (2nd generation)...
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following FormatException was thrown building GalleryApp(dirty):
flutter: FormatException
flutter:
flutter: The relevant error-causing widget was:
flutter:   GalleryApp file:///Users/helinx/Documents/gallery/lib/main.dart:20:16
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      GalleryApp.build (package:gallery/main.dart:35:5)
flutter: #1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4580:28)
flutter: #2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4506:15)
flutter: #3      Element.rebuild (package:flutter/src/widgets/framework.dart:4222:5)
flutter: #4      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4485:5)
flutter: #5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4480:5)
flutter: #6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3450:14)
flutter: #7      Element.updateChild (package:flutter/src/widgets/framework.dart:3218:18)
flutter: #8      RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1130:16)
flutter: #9      RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1101:5)
flutter: #10     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1043:17)
flutter: #11     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)
flutter: #12     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1042:13)
flutter: #13     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:923:7)
flutter: #14     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:904:7)
flutter: (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
flutter:
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════

════════ 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:20:16
When the exception was thrown, this was the stack: 
#0      GalleryApp.build (package:gallery/main.dart:35:5)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4580:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4506:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4222:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

Run output after change:

Launching lib/main.dart on iPhone SE (2nd generation) in debug mode...
Running Xcode build...
Xcode build done.                                           33.8s
Waiting for iPhone SE (2nd generation) to report its views...
Debug service listening on ws://127.0.0.1:55771/43D3tM6g8xM=/ws
Syncing files to device iPhone SE (2nd generation)...

════════ 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      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2632:33)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

Related Issues

(None - should I file one?)

Tests

I added the following tests:

  • Check that error events are received after setStructuredErrors has been called

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.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

cc @jacob314

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label May 27, 2020
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 with a couple nits.
lgtm

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

@helin24 helin24 merged commit 479f370 into flutter:master May 28, 2020
@helin24 helin24 deleted the structured-errors branch May 28, 2020 23:38
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants