From 6f0d2c1f0a88c9960f93d1e41bc4e657fe6a70ba Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 12 Mar 2024 09:24:55 +0100 Subject: [PATCH] Apply some defensive programming We have logs that retrieving the `accessToken` would crash Cura. By adding some defensive programming, in combination with proper error logging the crash no longer happens, and as programmers we have proper logging where the error occurred. CURA-11640 --- cura/API/Account.py | 6 +++++- cura/UltimakerCloud/UltimakerCloudScope.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index 2651037e9e..2d3023d072 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -275,7 +275,11 @@ class Account(QObject): @pyqtProperty(str, notify=accessTokenChanged) def accessToken(self) -> Optional[str]: - return self._authorization_service.getAccessToken() + try: + return self._authorization_service.getAccessToken() + except Exception as e: + Logger.error("Failed to get access token: %s", str(e)) + return None @pyqtProperty("QVariantMap", notify = userProfileChanged) def userProfile(self) -> Dict[str, Optional[str]]: diff --git a/cura/UltimakerCloud/UltimakerCloudScope.py b/cura/UltimakerCloud/UltimakerCloudScope.py index a173c5c758..c30e1f7360 100644 --- a/cura/UltimakerCloud/UltimakerCloudScope.py +++ b/cura/UltimakerCloud/UltimakerCloudScope.py @@ -21,7 +21,7 @@ class UltimakerCloudScope(DefaultUserAgentScope): def __init__(self, application: "CuraApplication"): super().__init__(application) api = application.getCuraAPI() - self._account = api.account # type: Account + self._account: Account = api.account def requestHook(self, request: QNetworkRequest): super().requestHook(request)