Skip to content

Commit

Permalink
fix(update-check): handle internet connection errors in update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
amnweb committed Oct 29, 2024
1 parent 1615e0b commit e88a1e6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/widgets/yasb/update_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ def get_windows_update(self):
update_names = [update.Title for update in search_result.Updates if update.Title not in self._windows_update_exclude]
return {"count": count, "names": update_names}
return {"count": 0, "names": []}
except win32com.client.pywintypes.com_error:
logging.error("No internet connection. Unable to check for Windows updates.")
return {"count": 0, "names": []}
except Exception as e:
logging.error(f"Error running windows update: {e}")
return {"count": 0, "names": []}

def get_winget_update(self):
try:
result = subprocess.run(
['winget', 'upgrade'],
['winget', 'upgrade','--no-cache'],
capture_output=True,
text=True,
check=True,
Expand Down Expand Up @@ -274,10 +278,15 @@ def get_winget_update(self):
update_names = [f"{software['name']} ({software['id']}): {software['version']} -> {software['available_version']}" for software in upgrade_list]
count = len(upgrade_list)
return {"count": count, "names": update_names}

except OSError:
logging.error("No internet connection. Unable to check for winget updates.")
return {"count": 0, "names": []}
except subprocess.CalledProcessError as e:
logging.error(f"Error running winget upgrade: {e}")
return {"count": 0, "names": []}
except Exception as e:
logging.error(f"Unexpected error: {e}")
return {"count": 0, "names": []}

def stop_updates(self):
self._stop_event.set()

0 comments on commit e88a1e6

Please sign in to comment.