Merge pull request #1426 from EDCD/fix/1393/eddn-codexentry_empty-string

eddn: Address EDDN server complains about some codexentry messages
This commit is contained in:
Athanasius authored and GitHub committed 2022-02-03 17:52:09 +00:00
commit 918272be3c
1 file changed
+37 -13
+37 -13
View File
@@ -802,7 +802,13 @@ class EDDN:
# If 'SystemName' or 'System' is there, it's directly from a journal event.
# If they're not there *and* 'StarSystem' isn't either, then we add the latter.
if 'SystemName' not in entry and 'System' not in entry and 'StarSystem' not in entry:
entry['StarSystem'] = system_name
if system_name is None or not isinstance(system_name, str) or system_name == '':
# Bad assumptions if this is the case
logger.warning(f'No system name in entry, and system_name was not set either! entry:\n{entry!r}\n')
return "passed-in system_name is empty, can't add System"
else:
entry['StarSystem'] = system_name
if 'SystemAddress' not in entry:
if this.systemaddress is None:
@@ -889,7 +895,7 @@ class EDDN:
this.eddn.export_journal_entry(cmdr, entry, msg)
return None
def export_journal_codexentry(
def export_journal_codexentry( # noqa: CCR001
self, cmdr: str, is_beta: bool, entry: MutableMapping[str, Any]
) -> Optional[str]:
"""
@@ -937,14 +943,30 @@ class EDDN:
entry = ret
# Set BodyName if it's available from Status.json
if this.status_body_name is not None:
if this.status_body_name is None or not isinstance(this.status_body_name, str):
logger.warning(f'this.status_body_name was not set properly:'
f' "{this.status_body_name}" ({type(this.status_body_name)})')
else:
entry['BodyName'] = this.status_body_name
# Only set BodyID if journal BodyName matches the Status.json one.
# This avoids binary body issues.
if this.status_body_name == this.body_name:
entry['BodyID'] = this.body_id
if this.body_id is not None and isinstance(this.body_id, int):
entry['BodyID'] = this.body_id
else:
logger.warning(f'this.body_id was not set properly: "{this.body_id}" ({type(this.body_id)})')
#######################################################################
for k, v in entry.items():
if v is None or isinstance(v, str) and v == '':
logger.warning(f'post-processing entry contains entry["{k}"] = {v} {(type(v))}')
# We should drop this message and VERY LOUDLY inform the
# user, in the hopes they'll open a bug report with the
# raw Journal event that caused this.
return 'CodexEntry had empty string, PLEASE ALERT THE EDMC DEVELOPERS'
msg = {
'$schemaRef': f'https://eddn.edcd.io/schemas/codexentry/1{"/test" if is_beta else ""}',
'message': entry
@@ -1413,15 +1435,15 @@ def journal_entry( # noqa: C901, CCR001
# add mandatory StarSystem, StarPos and SystemAddress properties to Scan events
if 'StarSystem' not in entry:
if not system:
logger.warning("system is None, can't add StarSystem")
return "system is None, can't add StarSystem"
logger.warning("system is falsey, can't add StarSystem")
return "system is falsey, can't add StarSystem"
entry['StarSystem'] = system
if 'StarPos' not in entry:
if not this.coordinates:
logger.warning("this.coordinates is None, can't add StarPos")
return "this.coordinates is None, can't add StarPos"
logger.warning("this.coordinates is falsey, can't add StarPos")
return "this.coordinates is falsey, can't add StarPos"
# Gazelle[TD] reported seeing a lagged Scan event with incorrect
# augmented StarPos: <https://github.com/EDCD/EDMarketConnector/issues/961>
@@ -1433,8 +1455,8 @@ def journal_entry( # noqa: C901, CCR001
if 'SystemAddress' not in entry:
if not this.systemaddress:
logger.warning("this.systemaddress is None, can't add SystemAddress")
return "this.systemaddress is None, can't add SystemAddress"
logger.warning("this.systemaddress is falsey, can't add SystemAddress")
return "this.systemaddress is falsey, can't add SystemAddress"
entry['SystemAddress'] = this.systemaddress
@@ -1590,10 +1612,12 @@ def dashboard_entry(cmdr: str, is_beta: bool, entry: Dict[str, Any]) -> None:
:param is_beta: Whether non-live game version was detected.
:param entry: The latest Status.json data.
"""
this.status_body_name = None
if 'BodyName' in entry:
this.status_body_name = entry['BodyName']
if not isinstance(entry['BodyName'], str):
logger.warning(f'BodyName was present but not a string! "{entry["BodyName"]}" ({type(entry["BodyName"])})')
else:
this.status_body_name = None
else:
this.status_body_name = entry['BodyName']
tracking_ui_update()