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

Improve exception handling #628

Merged
merged 31 commits into from
Dec 16, 2020
Merged

Improve exception handling #628

merged 31 commits into from
Dec 16, 2020

Conversation

samuel-w
Copy link
Contributor

@samuel-w samuel-w commented Sep 8, 2020

Still exits on uncaught exception, which is same as before.
Should we translate the log message? Just the "Uncaught exception, file a report on GitHub"
Fixes #621

Example, from #619:

2020-09-07 20:52:17,851 - root - ERROR - Uncaught exception, file a report on GitHub:
Traceback (most recent call last):
  File "/home/user/Projects/vorta/src/vorta/application.py", line 90, in open_main_window_action
    self.main_window = MainWindow(self)
  File "/home/user/Projects/vorta/src/vorta/views/main_window.py", line 94, in __init__
    self.set_status(self.tr('Backup in progress.'))
AttributeError: 'MainWindow' object has no attribute 'set_status'

@samuel-w samuel-w marked this pull request as draft September 8, 2020 02:56
@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

Works as expected

2020-09-08 10:59:17,093 - root - ERROR - Uncaught exception, file a report on GitHub:
Traceback (most recent call last):
  File "/Users/manu/Workspace/vorta/src/vorta/borg/borg_thread.py", line 162, in run
    self.started_event()
  File "/Users/manu/Workspace/vorta/src/vorta/borg/create.py", line 41, in started_event
    raise Exception('Buha')
Exception: Buha
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
zsh: segmentation fault  vorta

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

How about putting the issue URL to make it even easier?

https://github.com/borgbase/vorta/issues/new

samuel-w and others added 2 commits September 7, 2020 22:15
This makes it so that exceptions which don't cause a crash not exit,
while exceptions that do cause a crash exit. However, it does print to
console twice, which might be weird.
@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

The issue I'm having is some exceptions don't cause a crash, while others do cause a crash, and I can't differentiate them.

Should we always crash on uncaught exceptions?

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

Which exceptions don't crash? Maybe they are caught somewhere? I wouldn't crash the app more often than we have to.

Another idea would be to open a window showing the exception and offering to direct it to Github? (prefill?)

src/vorta/__main__.py Outdated Show resolved Hide resolved
@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

Now it double prints the exception to the terminal. Should be fine for reading bug reports.

@samuel-w samuel-w marked this pull request as ready for review September 8, 2020 06:40
@samuel-w samuel-w marked this pull request as draft September 8, 2020 06:43
@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

I've decided to always close on uncaught exception because it makes the behaviour more consistent across platforms, such as #613 and #521, where one crashes and the other does not, but both lead to undesired behaviour.

logger.critical("Uncaught exception, file a report at https://github.com/borgbase/vorta/issues/new:",
exc_info=(type, value, tb))
sys.__excepthook__(type, value, tb)
sys.exit(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove this line to make uncaught exceptions never crash, may lead to undesired behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine. Lets crash it all the time. At least we get bug reports quickly.

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've made the exception print a notification. Should I still create a crash?

@samuel-w samuel-w marked this pull request as ready for review September 8, 2020 06:54
@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

Sample notification:
example

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

How about a real UI window in Qt that has the exception and Github link?

Else we start with just adding it to the logs. Not sure a notification is useful since it can't be clicked and may be disabled.

@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

This is what is displayed now, exception is generated:
example
It only happens when the exception is in the foreground, if its in the background it just prints to log.
Text can be copied.

@samuel-w samuel-w changed the title Log exceptions in log Improve exception handling Sep 8, 2020
@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

Good solution. Last suggestion: Move the "File a bug report on github.com/..." into the alert, so it can be a real link? Then only the actual exception is logged.

@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

It gets cutoff though.
example

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

It gets cutoff though.
example

Better add it inside the message, rather than as title. Title could be "Uncaught exception" or something?

@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

Adding a link destroys formatting.
example

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

Because HTML removes line breaks unless there is a <br>.

Still possible to make the alert a more complex UI element with two separate text widgets. Probably even possible programmatically without doing a .ui file.

@samuel-w
Copy link
Contributor Author

samuel-w commented Sep 8, 2020

There is a way to automate filling out a bug report with https://github.com/borgbase/vorta/issues/new?title=&body=. We could use that, but it seems like too much work compared to copying and pasting.

Edit: Especially for something that most users aren't going to see

@m3nu
Copy link
Contributor

m3nu commented Sep 8, 2020

I expected there to be some URL parameters, like for mailto links. I think for now it's already a great improvement if those exceptions end up a) in the logs and b) in a message window when a crash happens.

src/vorta/__main__.py Outdated Show resolved Hide resolved
m3nu and others added 5 commits September 9, 2020 08:48
Because we have a message pop up now there is no need to close, unless
Vorta is in the background, where we close to prevent it from freezing
up and having to be force closed
@codecov-io
Copy link

codecov-io commented Dec 13, 2020

Codecov Report

Merging #628 (0a24aea) into master (19b4946) will decrease coverage by 0.21%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #628      +/-   ##
==========================================
- Coverage   74.48%   74.27%   -0.22%     
==========================================
  Files          53       53              
  Lines        3422     3432      +10     
==========================================
  Hits         2549     2549              
- Misses        873      883      +10     
Impacted Files Coverage Δ
src/vorta/__main__.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19b4946...0a24aea. Read the comment docs.

@m3nu m3nu self-assigned this Dec 15, 2020
@m3nu m3nu merged commit d6f368a into borgbase:master Dec 16, 2020
@samuel-w samuel-w deleted the LogExeceptions branch December 16, 2020 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exceptions not logged in logs
3 participants