mu-editor / mu

A small, simple editor for beginner Python programmers. Written in Python and Qt5.
http://codewith.mu
GNU General Public License v3.0
1.41k stars 435 forks source link

Mu should be crash-friendly #964

Open tmontes opened 4 years ago

tmontes commented 4 years ago

(as suggested by @ntoll here)

Issue

Idea

Facts

Thoughts

I feel this is a very important and non-trivial issue that we should seriously consider including, for the benefit of both Mu users and contributors: such tooling should lead to a better user experience and to more detailed, hopefully actionable, crash reports that contributors can address directly. :)

Shall we discuss this?

tjg-global commented 4 years ago

Definite +1 for me -- although without any concrete proposal to make at present. (Apart from the obvious try-except approach which you say has complications through the Qt event loop).

Just dropping in here (as part of any wider discussion): https://docs.python.org/3/library/sys.html#sys.excepthook

dlech commented 4 years ago

Could we create a "runner" program that runs Mu as a subprocess and displays a message if the exit code is non-zero? This would catch everything, even segmentation faults.

Example:

import pathlib
import subprocess
import sys

args = [
    sys.executable,
    str(pathlib.Path(__file__.replace('runner.py', 'main.py')).absolute()),
    # TODO: append additional command line args from sys.argv
]

with open('log.txt', 'w') as log:
    ret = subprocess.run(args, stderr=log)
    if ret.returncode:
        # TODO: Use Qt to show this in dialog box along with a button to
        # automatically send log.txt somewhere or view it locally
        print('Something bad happened')
        sys.exit(ret.returncode)

We could still run Mu directly for development/debug, but in production, it could be run with such a wrapper.

tjg-global commented 4 years ago

@dlech The idea is attractive. My initial misgiving would be that any additional mechanism adds a layer of uncertainty / risk which provides yet another source of possible bugs. In other words, we'd have to be absolutely certain that the additional (support / debugging) overhead was outweighed by the benefits.

tmontes commented 4 years ago

My ad-hoc exploration in a different context lead me to this project, which might be useful in this context: qcrash @PyPI and @GitHub...

While not exactly the approach @dlech was mentioning, it may help address the majority of crashes we've observed with, hopefully, very little effort on our part.

Deferring evaluation to a later stage. Just wanted to "write it down" and share.

tmontes commented 4 years ago

I dedicated some time to explore the above mentioned qcrash library. For that, I created a minimal project I called qtcrashme. Here are my findings.

The experience

Running qtcrashme gets us this window:

Screen Shot 2019-12-04 at 12 47 04

Clicking the Click to crash button triggers a raise BaseException(...) here. With qcrash it is caught and a default "something bad happend" dialog is displayed:

Screen Shot 2019-12-04 at 12 48 22

Clicking the Show Details... button expands the dialog to include the traceback:

Screen Shot 2019-12-04 at 12 52 55

Clicking the Report button closes that dialog and brings up a new one, again bundled within qcrash, with a pre-filled Title and an empty Description area for the user to enter text:

Screen Shot 2019-12-04 at 12 55 04

As soon as some input is added to the Description, the Submit on github and Send email buttons become active:

Screen Shot 2019-12-04 at 12 56 05

Clicking the Send email button triggers the default email client with a ready to send email message. Here's what I got in my case:

Screen Shot 2019-12-04 at 12 58 25

Clicking the Submit on github button instead brings up yet another qcrash bundled dialog, allowing the user to review what will be submitted to GitHub, including the issue text...

Screen Shot 2019-12-04 at 13 00 41

...and the log, which will be submitted as a linked gist:

Screen Shot 2019-12-04 at 13 00 48

Lastly, clicking the OK button, brings up yet another dialog asking for the user's GitHub credentials, such that a new issue can be logged on their behalf:

Screen Shot 2019-12-04 at 13 03 55

No feedback is given as the GitHub API interaction progresses. It felt like ~3-5 seconds on my attempts. Once done, a final qcrash dialog is shown:

Screen Shot 2019-12-04 at 13 05 15

Clicking the Yes button, takes you to the just logged issue which, interestingly, links to the gist containing the log file contents.

Once this process is complete, the original UI is available and running -- whether it is still of any use after such failure will depend on the code, naturally. :)

What I like

What I don't like

What prompts discussion

Wrap up

This was interesting. Like I initially wrote, I think the key thing is coming up with a good answer to:

The kind of Mu behaviour when such fatal failures are detected needs to be defined. What should happen? Which kinds of end user interaction would make sense?

From there, everything else becomes a "technical detail". :)

ZanderBrown commented 4 years ago

If the dialog is coming from the same instance as mu itself using our theme should be fairly trivial, otherwise it may require a little more investigation

Overall that UX isn't overly great but hopefully it doesn't get seen often

dybber commented 3 years ago

Ideally, the user would just hit report and then the crash log would be directly submitted to Github as an issue. Here's a Github app that receives emails and creates issues: https://fire.fundersclub.com/ - do you it could be misused for spam, or does Github do effective spam filtering?