Skip to content

Suggest GitHub template when flutter tool crashes#45360

Merged
jmagman merged 5 commits intoflutter:masterfrom
jmagman:report
Nov 26, 2019
Merged

Suggest GitHub template when flutter tool crashes#45360
jmagman merged 5 commits intoflutter:masterfrom
jmagman:report

Conversation

@jmagman
Copy link
Copy Markdown
Member

@jmagman jmagman commented Nov 21, 2019

Description

When the Flutter tool crashes, suggest a GitHub template that contains the command, stacktrace, flutter doctor -v, and some metadata if the working directory is a Flutter project.

I discussed with @InMatrix and he suggested we not show the "Sending crash report to Google." with the report ID by default, because users will think they don't need to report their crash because something was automatically sent, so I moved that line to a trace log.

Also, usesAndroidX was crashing if the module section wasn't present, so I fixed that.

The GitHub URL has been shortened with GitHub's URL shortener API.

Example

I faked out a crash.

$ flutter logs -d d83d5bc53967baa0ee18626ba87b6254b2ab5418

Oops; flutter has exited unexpectedly: "Exception: VersionCheckError: Command exited with code -9: git log -n 1
--pretty=format:%ad --date=iso".
A crash report has been written to /Users/m/Projects/test_create_swift/flutter_08.log.
This crash may already be reported. Check GitHub for similar crashes.
https://git.io/JePo1

To report your crash to the Flutter team, first read the guide to filing a bug.
https://flutter.dev/docs/resources/bug-reports

Create a new GitHub issue by pasting this link into your browser and completing the issue template. Thank you!
https://git.io/JePia

And here's what it looks like visually to the user:
Screen Shot 2019-11-25 at 4 34 47 PM

And here's the GitHub template when you click on that big link (try it!):

Title
[tool_crash] Exception: VersionCheckError: Command exited with code -9: git log -n 1 --pretty=format:%ad --date=iso
===========BODY START===========

Command

flutter logs -d 389148FB-E436-4F8B-B37A-8564AF1627C0

Steps to Reproduce

  1. ...
  2. ...
  3. ...

Logs

_Exception: Exception: VersionCheckError: Command exited with code -9: git log -n 1 --pretty=format:%ad --date=iso

#0      LogsCommand.runCommand (package:flutter_tools/src/commands/logs.dart:46:5)
#1      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:600:18)
<asynchronous suspension>
#2      LogsCommand.verifyThenRunCommand (package:flutter_tools/src/commands/logs.dart:40:18)
<asynchronous suspension>
#3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:500:33)
<asynchronous suspension>
#4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#5      _rootRun (dart:async/zone.dart:1126:13)
#6      _CustomZone.run (dart:async/zone.dart:1023:19)
#7      _runZoned (dart:async/zone.dart:1518:10)
#8      runZoned (dart:async/zone.dart:1465:12)
#9      AppContext.run (package:flutter_tools/src/base/context.dart:145:18)
#10     FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:490:20)
#11     CommandRunner.runCommand (package:args/command_runner.dart:197:27)
#12     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:416:21)
<asynchronous suspension>
#13     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#14     _rootRun (dart:async/zone.dart:1126:13)
#15     _CustomZone.run (dart:async/zone.dart:1023:19)
[✓] Flutter (Channel unknown, v1.12.8-pre.7, on Mac OS X 10.14.6 18G87, locale en-US)
    • Flutter version 1.12.8-pre.7 at /Users/m/Projects/flutter
    • Framework revision a152c2c334 (12 minutes ago), 2019-11-21 13:00:17 -0800
    • Engine revision 7a77e3625d
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/m/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2)
    • Xcode at /Users/m/Applications/Xcode-11_2.app/Contents/Developer
    • Xcode 11.2, Build version 11B41
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 40.2.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Community Edition (version 2019.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 41.1.3
    • Dart plugin version 192.7402

[✓] VS Code (version 1.40.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 389148FB-E436-4F8B-B37A-8564AF1627C0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-2 (simulator)

• No issues found!

Flutter Application Metadata

Version: 1.0.0+1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null

Plugins

camera

===========BODY END===========

(The ===========BODY=========== ASCII art isn't in there, it's to try to make this issue-in-PR description easier to see)

Possible Future Work

  1. Use URL shortener for that long link (cons: networking while crashing, though we do send that crash report). Done!
  2. Check GitHub for related issues and actually print the top 3 sorted by reaction (cons: networking while crashing).
  3. Work with IDE teams to give a better hook into this, i.e. a popup with button to file the crash.
  4. Plugin versions.

Related Issues

Fixes #44126.
Fixes #45617.

Tests

Added a runner test, added new GitHub template tests, fixed up a few others based on the new input.
Added usesAndroidX tests.

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

  • Yes, this is a breaking change (Please read [Handling breaking changes]). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@jmagman jmagman added c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. a: triage improvements Make GitHub issues easier to triage and more actionable labels Nov 21, 2019
@jmagman jmagman self-assigned this Nov 21, 2019
Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted this to be printError but when I changed it to that it always printed before some of the above status lines. I'm guessing stderr has more aggressive flush behavior, and none of the stdout flushes I tried seemed to help. Open to suggestions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately it looks like dart:io stdout.flush() only flushes any buffering in Dart's memory. It doesn't actually result in a flush() call on the underlying fd to the OS.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm okay with an angry-looking red status.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I switched this back to an error at the top since now the output is much smaller and I'm less worried about it getting scrolled out of view.

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping this vanilla and bland: something Bad is happening.

Comment thread packages/flutter_tools/lib/src/doctor.dart Outdated
Copy link
Copy Markdown
Contributor

@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.

This is great. Just took a quick look so far

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

I love this change.

My biggest concern is that the length of the URL will discourage folks from copying it into their browser.

W.r.t. hitting the network while crashing, we can print a big URL if that fails, for example.

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately it looks like dart:io stdout.flush() only flushes any buffering in Dart's memory. It doesn't actually result in a flush() call on the underlying fd to the OS.

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hopefully the doctor won't crash, but I think it would be good to guard against it separately and continue with printing the github issue instructions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

doctor exceptions are already caught in _doctorText.

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider whether moving some or all of the code under the else on 115 into a separate method would improve readability of _handleToolError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There was enough complicated try/catch and early returns that I just pulled out the wall-o-text part. Hopefully that makes it readable enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved it into its own file.

Comment thread packages/flutter_tools/lib/src/doctor.dart Outdated
Comment thread packages/flutter_tools/test/general.shard/runner/runner_test.dart Outdated
@jmagman
Copy link
Copy Markdown
Member Author

jmagman commented Nov 22, 2019

I love this change.

My biggest concern is that the length of the URL will discourage folks from copying it into their browser.

W.r.t. hitting the network while crashing, we can print a big URL if that fails, for example.

@zanderso Are you cool with that being a future improvement, or do you want the URL shortening in this PR?

@zanderso
Copy link
Copy Markdown
Member

@zanderso Are you cool with that being a future improvement, or do you want the URL shortening in this PR?

If you can do it in this PR that would be great. If splitting it up makes life a lot easier, I would prefer that this not land until after the current release cycle so we don't have the big URLs on stable.

@jmagman
Copy link
Copy Markdown
Member Author

jmagman commented Nov 26, 2019

If you can do it in this PR that would be great. If splitting it up makes life a lot easier, I would prefer that this not land until after the current release cycle so we don't have the big URLs on stable.

@zanderso
I have the git.io shortener working. Here's what it looks like now:

$ flutter logs -d d83d5bc53967baa0ee18626ba87b6254b2ab5418

Oops; flutter has exited unexpectedly: "Exception: VersionCheckError: Command exited with code -9: git log -n 1
--pretty=format:%ad --date=iso".
A crash report has been written to /Users/m/Projects/test_create_swift/flutter_08.log.
This crash may already be reported. Check GitHub for similar crashes.
https://git.io/JePo1

To report your crash to the Flutter team, first read the guide to filing a bug.
https://flutter.dev/docs/resources/bug-reports

Create a new GitHub issue by pasting this link into your browser and completing the issue template. Thank you!
https://git.io/JePia

Screen Shot 2019-11-25 at 4 34 47 PM

Copy link
Copy Markdown
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm w/ nits

Comment thread packages/flutter_tools/lib/runner.dart Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Long lines like this can be split up like:

  final String gitHubTemplateURL = await gitHubTemplateCreator.toolCrashIssueTemplateGitHubURL(
    command,
    errorString,
    _crashException(error),
    stackTrace,
    doctorText,
  );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  Future<String> toolCrashIssueTemplateGitHubURL(
    String command,
    String errorString,
    String exception,
    StackTrace stackTrace,
    String doctorText
  ) async {
    ...
  }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like manifest has already been checked for null above on line 77.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Best to wrap these file system calls in a try-catch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

extra newline

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Formatting nit: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#if-you-have-a-newline-after-some-opening-punctuation-match-it-on-the-closing-punctuation

expect(
  await creator.toolCrashSimilarIssuesGitHubURL('this is a 100% error'),
  _kShortURL,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jmagman jmagman merged commit 7d8f820 into flutter:master Nov 26, 2019
@jmagman jmagman deleted the report branch November 26, 2019 22:06
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 1, 2021
final List<int> bodyBytes = utf8.encode('url=${Uri.encodeQueryComponent(fullURL)}');
final HttpClientRequest request = await _client.postUrl(Uri.parse('https://git.io'));
request.headers.set(HttpHeaders.contentLengthHeader, bodyBytes.length.toString());
request.add(bodyBytes);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't realize this code existed until just now... surely this is potentially sending PII to GitHub? This seems like a problem.

@zanderso
Copy link
Copy Markdown
Member

My recollection is that the information is sanitized to contain only information about tool internals e.g. a sanitized exception message and a stack trace containing only flutter_tool frames, but @jmagman and @christopherfujino should verify.

We should also revisit whether this has improved the quality of filed issues. Maybe @stuartmorgan can help us ask the triagers if issues filed with this template have good signal.

@zanderso
Copy link
Copy Markdown
Member

For reference here is an example #54213

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

We should also revisit whether this has improved the quality of filed issues. Maybe @stuartmorgan can help us ask the triagers if issues filed with this template have good signal.

I can ask, but given that the audience for the stack information is primarily the tools team, not first-stage triagers, wouldn't having the tools team audit https://github.com/flutter/flutter/issues?q=is%3Aissue+tool_crash+in%3Atitle for value tell us more about how well the template works?

@Hixie
Copy link
Copy Markdown
Contributor

Hixie commented Dec 29, 2021

It includes paths (which can include usernames), device IDs, potentially private plugin names, potentially sensitive arguments...

@Hixie
Copy link
Copy Markdown
Contributor

Hixie commented Dec 29, 2021

For the record I've nothing against us filing bugs with this information, it's only the short link creation that's a problem because we don't prompt the user before uploading the information.

@jmagman
Copy link
Copy Markdown
Member Author

jmagman commented Jan 5, 2022

See #53140 for discussion about removing the URL shortener.

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

We should also revisit whether this has improved the quality of filed issues. Maybe @stuartmorgan can help us ask the triagers if issues filed with this template have good signal.

Feedback is the template is providing good signal (ability to effectively dup, avoiding round-trip requests for more information, etc.). So eliminating it completely would definitely not be ideal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: triage improvements Make GitHub issues easier to triage and more actionable c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter build crash not chatty Tool error output should include a proposed GitHub issue template

6 participants