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

PR: Catch error when checking for updates (Update Manager) #23420

Merged
merged 7 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions spyder/plugins/updatemanager/widgets/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def _process_check_update(self):
# Get results from worker
update_available = self.update_worker.update_available
error_msg = self.update_worker.error
checkbox = self.update_worker.checkbox

# Always set status, regardless of error, DEV, or startup
self.set_status(PENDING if update_available else NO_STATUS)
Expand All @@ -243,7 +244,7 @@ def _process_check_update(self):
# Do not alert the user to anything
pass
elif error_msg is not None:
error_messagebox(self, error_msg)
error_messagebox(self, error_msg, checkbox)
elif update_available:
self.start_update()
else:
Expand Down Expand Up @@ -532,10 +533,11 @@ def update_progress(self, progress, total):
self._progress_bar.setValue(progress)


def error_messagebox(parent, error_msg):
box = UpdateMessageBox(
icon=QMessageBox.Warning, text=error_msg, parent=parent
)
def error_messagebox(parent, error_msg, checkbox=False):
# Use a message box with a checkbox to disable updates when required, or a
# standard one otherwise.
box_class = UpdateMessageCheckBox if checkbox else UpdateMessageBox
box = box_class(icon=QMessageBox.Warning, text=error_msg, parent=parent)
box.setWindowTitle(_("Spyder update error"))
box.setStandardButtons(QMessageBox.Ok)
box.setDefaultButton(QMessageBox.Ok)
Expand Down
11 changes: 11 additions & 0 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
'<br><br>Please contact your network administrator for assistance.'
)

OS_ERROR_MSG = _(
"An error occurred while checking for Spyder updates, possibly related to "
"your operating system configuration or file access.<br><br>If you're not "
"sure what to do about it, you can disable checking for updates below. "
"<br><br>The error was:<br><br><i>{error}</i>"
)

def _rate_limits(page):
"""Log rate limits for GitHub.com"""
Expand Down Expand Up @@ -190,6 +196,7 @@ def __init__(self, stable_only):
self.latest_release = None
self.update_available = False
self.error = None
self.checkbox = False
self.channel = None

def _check_update_available(
Expand Down Expand Up @@ -294,6 +301,10 @@ def start(self):
except HTTPError as err:
error_msg = HTTP_ERROR_MSG.format(status_code=page.status_code)
logger.warning(err, exc_info=err)
except OSError as err:
error_msg = OS_ERROR_MSG.format(error=err)
self.checkbox = True
logger.warning(err, exc_info=err)
except Exception as err:
# Send untracked errors to our error reporter
error_data = dict(
Expand Down
Loading