From 67a91cf7d13042716cbd9a05550d78820381a44f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 5 Mar 2021 16:57:02 +0000 Subject: [PATCH] CAPI: Handle when we get no 'commander' in returned data. I was testing the new Steam or Epic CAPI auth. My EGS account hasn't yet been used, so has no commander attached. EDMC thinks the auth has succeeded in this case, but hitting 'Update' causes it to error because the returned data is empty. So, add some checks for lack of 'commander' key and a specific message "CAPI: No commander data returned" for status line. Without this there's a KeyError exception thrown, causing the status line to just get 'commander' in it, which isn't helpful. --- EDMarketConnector.py | 10 +++++++++- L10n/en.template | 3 +++ companion.py | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 73f15e67..6f4b8c7c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -662,17 +662,25 @@ class AppWindow(object): config.set('querytime', querytime) # Validation - if not data.get('commander', {}).get('name'): + if 'commander' not in data: + # This can happen with EGS Auth if no commander created yet + self.status['text'] = _('CAPI: No commander data returned') + + elif not data.get('commander', {}).get('name'): self.status['text'] = _("Who are you?!") # Shouldn't happen + elif (not data.get('lastSystem', {}).get('name') or (data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): # Only care if docked self.status['text'] = _("Where are you?!") # Shouldn't happen + elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'): self.status['text'] = _("What are you flying?!") # Shouldn't happen + elif monitor.cmdr and data['commander']['name'] != monitor.cmdr: # Companion API return doesn't match Journal raise companion.CmdrError() + elif ((auto_update and not data['commander'].get('docked')) or (data['lastSystem']['name'] != monitor.system) or ((data['commander']['docked'] diff --git a/L10n/en.template b/L10n/en.template index 23b4abcd..ef8f7399 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -46,6 +46,9 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Browse..."; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: No commander data returned"; + /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; diff --git a/companion.py b/companion.py index b75d39ae..ba8faf1a 100644 --- a/companion.py +++ b/companion.py @@ -532,6 +532,10 @@ class Session(object): def station(self) -> CAPIData: """Perform CAPI /profile endpoint query for station data.""" data = self.query(URL_QUERY) + if 'commander' not in data: + logger.error('No commander in returned data') + return data + if not data['commander'].get('docked'): return data