Skip to content

Commit

Permalink
Merge pull request #23420 from jsbautista/checkingUpdates
Browse files Browse the repository at this point in the history
PR: Catch error when checking for updates (Update Manager)
  • Loading branch information
ccordoba12 authored Jan 15, 2025
2 parents dbb946f + d7ef309 commit 1e20d17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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

0 comments on commit 1e20d17

Please sign in to comment.