66from lrucache import LRUCache
77from edrlog import EDR_LOG
88from edentities import EDPlayerOne
9-
10-
9+ from edrserver import CommsJammedError
1110
1211
1312class EDRCmdrs (object ):
@@ -66,7 +65,11 @@ def player_pledged_to(self, power, time_pledged=0):
6665 return False
6766 self ._player .pledged_to (power , time_pledged )
6867 since = self ._player .pledged_since ()
69- return self .server .pledged_to (power , since )
68+ try :
69+ return self .server .pledged_to (power , since )
70+ except CommsJammedError :
71+ EDR_LOG .log (u"Comms jammed: Failed to update pledge status to EDR." , "WARNING" )
72+ return False
7073
7174 def __squadron_id (self ):
7275 self .__update_squadron_info ()
@@ -78,7 +81,13 @@ def __update_squadron_info(self, force_update=False):
7881 return
7982 mark_twain_flag = int ((EDTime .js_epoch_now () - self .heartbeat_timestamp )/ 1000 ) >= self ._edr_heartbeat if self .heartbeat_timestamp else True
8083 if force_update or mark_twain_flag :
81- info = self .server .heartbeat ()
84+ info = None
85+ try :
86+ info = self .server .heartbeat ()
87+ except CommsJammedError :
88+ EDR_LOG .log (u"Comms jammed: Failed to get heartbeat from EDR." , "WARNING" )
89+ info = None
90+
8291 if info :
8392 self .heartbeat_timestamp = info ["heartbeat" ] if "heartbeat" in info else EDTime .js_epoch_now ()
8493 self ._player .squadron_member (info ) if "squadronId" in info else self ._player .lone_wolf ()
@@ -127,9 +136,12 @@ def __edr_cmdr(self, cmdr_name, autocreate):
127136
128137 try :
129138 profile = self .server .cmdr (cmdr_name , autocreate )
130- except :
131- EDR_LOG .log ("Exception during call to EDR server cmdr." , "WARNING" )
132- pass
139+ except CommsJammedError : # Refined exception handling
140+ EDR_LOG .log ("Comms jammed: Failed to fetch cmdr profile from EDR server." , "WARNING" )
141+ profile = None
142+ except Exception as e : # Catch other, unexpected exceptions
143+ EDR_LOG .log (f"Unexpected exception during call to EDR server cmdr: { e } " , "ERROR" )
144+ profile = None
133145
134146 if not profile :
135147 if backup_profile :
@@ -141,11 +153,18 @@ def __edr_cmdr(self, cmdr_name, autocreate):
141153 self .cmdrs_cache .set (cmdr_name .lower (), None )
142154 EDR_LOG .log (u"No match on EDR. Temporary entry to be nice on EDR's server." , "DEBUG" )
143155 return None
144- dex_profile = self .server .cmdrdex (profile .cid )
156+
157+ dex_profile = None
158+ try :
159+ dex_profile = self .server .cmdrdex (profile .cid )
160+ except CommsJammedError :
161+ EDR_LOG .log ("Comms jammed: Failed to fetch cmdr dex from EDR server." , "WARNING" )
162+ dex_profile = None
163+
145164 if dex_profile :
146- EDR_LOG .log (u"EDR CmdrDex entry found for {cmdr}: {id}" .format (cmdr = cmdr_name ,
147- id = profile .cid ), "DEBUG" )
165+ EDR_LOG .log (u"EDR CmdrDex entry found for {cmdr}: {id}" .format (cmdr = cmdr_name , id = profile .cid ), "DEBUG" )
148166 profile .dex (dex_profile )
167+
149168 self .cmdrs_cache .set (cmdr_name .lower (), profile )
150169 EDR_LOG .log (u"Cached EDR profile {cmdr}: {id}" .format (cmdr = cmdr_name ,
151170 id = profile .cid ), "DEBUG" )
@@ -167,7 +186,13 @@ def __edr_sqdrdex(self, cmdr_name, autocreate):
167186 if not profile :
168187 return None
169188
170- sqdrdex_dict = self .server .sqdrdex (sqdr_id , profile .cid )
189+ sqdrdex_dict = None
190+ try :
191+ sqdrdex_dict = self .server .sqdrdex (sqdr_id , profile .cid )
192+ except CommsJammedError :
193+ EDR_LOG .log ("Comms jammed: Failed to fetch squadron dex from EDR server." , "WARNING" )
194+ sqdrdex_dict = None
195+
171196 if sqdrdex_dict :
172197 EDR_LOG .log (u"EDR SqdrDex {sqid} entry found for {cmdr}@{cid}" .format (sqid = sqdr_id ,
173198 cmdr = cmdr_name , cid = profile .cid
@@ -189,7 +214,11 @@ def __inara_cmdr(self, cmdr_name, check_inara_server):
189214 "DEBUG" )
190215 elif check_inara_server :
191216 EDR_LOG .log (u"Stale {} or not cached {} in Inara cache. Inara API call for {}." .format (stale , cached , cmdr_name ), "INFO" )
192- inara_profile = self .server .inara_cmdr (cmdr_name )
217+ try : # New try-except for self.server.inara_cmdr(cmdr_name)
218+ inara_profile = self .server .inara_cmdr (cmdr_name )
219+ except CommsJammedError :
220+ EDR_LOG .log ("Comms jammed: Failed to fetch Inara profile via EDR server." , "WARNING" )
221+ inara_profile = None
193222
194223 if inara_profile and inara_profile .name .lower () == cmdr_name .lower ():
195224 self .inara_cache .set (cmdr_name .lower (), inara_profile )
@@ -256,7 +285,11 @@ def tag_cmdr(self, cmdr_name, tag):
256285 return self .__tag_cmdr (cmdr_name , tag )
257286
258287 def contracts (self ):
259- return self .server .contracts ()
288+ try :
289+ return self .server .contracts ()
290+ except CommsJammedError :
291+ EDR_LOG .log (u"Comms jammed: Failed to get contracts list." , "WARNING" )
292+ return None
260293
261294 def contract_for (self , cmdr_name ):
262295 if not cmdr_name :
@@ -266,7 +299,11 @@ def contract_for(self, cmdr_name):
266299 if not profile :
267300 return False
268301
269- return self .server .contract_for (profile .cid )
302+ try :
303+ return self .server .contract_for (profile .cid )
304+ except CommsJammedError :
305+ EDR_LOG .log (u"Comms jammed: Failed to get contract for {}." .format (cmdr_name ), "WARNING" )
306+ return False
270307
271308 def place_contract (self , cmdr_name , reward ):
272309 if not cmdr_name :
@@ -279,7 +316,11 @@ def place_contract(self, cmdr_name, reward):
279316 if not profile :
280317 return False
281318
282- return self .server .place_contract (profile .cid , {"cname" : cmdr_name .lower (), "reward" : reward })
319+ try :
320+ return self .server .place_contract (profile .cid , {"cname" : cmdr_name .lower (), "reward" : reward })
321+ except CommsJammedError :
322+ EDR_LOG .log (u"Comms jammed: Failed to place contract on {}." .format (cmdr_name ), "WARNING" )
323+ return False
283324
284325 def remove_contract (self , cmdr_name ):
285326 if not cmdr_name :
@@ -289,7 +330,11 @@ def remove_contract(self, cmdr_name):
289330 if not profile :
290331 return False
291332
292- return self .server .remove_contract (profile .cid )
333+ try :
334+ return self .server .remove_contract (profile .cid )
335+ except CommsJammedError :
336+ EDR_LOG .log (u"Comms jammed: Failed to remove contract on {}." .format (cmdr_name ), "WARNING" )
337+ return False
293338
294339 def __tag_cmdr (self , cmdr_name , tag ):
295340 EDR_LOG .log (u"Tagging {} with {}" .format (cmdr_name , tag ), "DEBUG" )
@@ -306,7 +351,14 @@ def __tag_cmdr(self, cmdr_name, tag):
306351
307352 dex_dict = profile .dex_dict ()
308353 EDR_LOG .log (u"New dex state: {}" .format (dex_dict ), "DEBUG" )
309- success = self .server .update_cmdrdex (profile .cid , dex_dict )
354+
355+ success = False
356+ try :
357+ success = self .server .update_cmdrdex (profile .cid , dex_dict )
358+ except CommsJammedError :
359+ EDR_LOG .log (u"Comms jammed: Failed to update EDR Dex for {}." .format (cmdr_name ), "WARNING" )
360+ success = False
361+
310362 self .evict (cmdr_name )
311363 return success
312364
@@ -333,7 +385,14 @@ def __squadron_tag_cmdr(self, cmdr_name, tag):
333385 augmented_sqdrdex_dict = sqdrdex_dict
334386 augmented_sqdrdex_dict ["level" ] = self ._player .squadron_info ()["squadronLevel" ]
335387 augmented_sqdrdex_dict ["by" ] = self ._player .name
336- success = self .server .update_sqdrdex (sqdr_id , profile .cid , augmented_sqdrdex_dict )
388+
389+ success = False # Initialize success before the try block
390+ try :
391+ success = self .server .update_sqdrdex (sqdr_id , profile .cid , augmented_sqdrdex_dict )
392+ except CommsJammedError :
393+ EDR_LOG .log (u"Comms jammed: Failed to update Squadron Dex (tag) for {}." .format (cmdr_name ), "WARNING" )
394+ success = False
395+
337396 self .evict (cmdr_name )
338397 return success
339398
@@ -353,7 +412,14 @@ def memo_cmdr(self, cmdr_name, memo):
353412 return False
354413
355414 dex_dict = profile .dex_dict ()
356- success = self .server .update_cmdrdex (profile .cid , dex_dict )
415+
416+ success = False # Initialize success
417+ try :
418+ success = self .server .update_cmdrdex (profile .cid , dex_dict )
419+ except CommsJammedError :
420+ EDR_LOG .log (u"Comms jammed: Failed to update EDR Dex (memo) for {}." .format (cmdr_name ), "WARNING" )
421+ success = False
422+
357423 self .evict (cmdr_name )
358424 return success
359425
@@ -371,7 +437,14 @@ def clear_memo_cmdr(self, cmdr_name):
371437 return False
372438
373439 dex_dict = profile .dex_dict ()
374- success = self .server .update_cmdrdex (profile .cid , dex_dict )
440+
441+ success = False # Initialize success
442+ try :
443+ success = self .server .update_cmdrdex (profile .cid , dex_dict )
444+ except CommsJammedError :
445+ EDR_LOG .log (u"Comms jammed: Failed to update EDR Dex (clear memo) for {}." .format (cmdr_name ), "WARNING" )
446+ success = False
447+
375448 self .evict (cmdr_name )
376449 return success
377450
@@ -396,7 +469,14 @@ def __untag_cmdr(self, cmdr_name, tag):
396469
397470 dex_dict = profile .dex_dict ()
398471 EDR_LOG .log (u"New dex state: {}" .format (dex_dict ), "DEBUG" )
399- success = self .server .update_cmdrdex (profile .cid , dex_dict )
472+
473+ success = False # Initialize success
474+ try :
475+ success = self .server .update_cmdrdex (profile .cid , dex_dict )
476+ except CommsJammedError :
477+ EDR_LOG .log (u"Comms jammed: Failed to update EDR Dex (untag) for {}." .format (cmdr_name ), "WARNING" )
478+ success = False
479+
400480 self .evict (cmdr_name )
401481 return success
402482
@@ -423,6 +503,13 @@ def __squadron_untag_cmdr(self, cmdr_name, tag):
423503 augmented_sqdrdex_dict = sqdrdex_dict
424504 augmented_sqdrdex_dict ["level" ] = self ._player .squadron_info ()["squadronLevel" ]
425505 augmented_sqdrdex_dict ["by" ] = self ._player .name
426- success = self .server .update_sqdrdex (sqdr_id , profile .cid , augmented_sqdrdex_dict )
506+
507+ success = False # Initialize success
508+ try :
509+ success = self .server .update_sqdrdex (sqdr_id , profile .cid , augmented_sqdrdex_dict )
510+ except CommsJammedError :
511+ EDR_LOG .log (u"Comms jammed: Failed to update Squadron Dex (untag) for {}." .format (cmdr_name ), "WARNING" )
512+ success = False
513+
427514 self .evict (cmdr_name )
428515 return success
0 commit comments