From d83a1c514d15899f0752abcbd55a45c38aa2f133 Mon Sep 17 00:00:00 2001
From: Athanasius <github@miggy.org>
Date: Thu, 3 Feb 2022 15:33:34 +0000
Subject: [PATCH] eddn: Log if a 'location' event doesn't have SystemAddress

It *really* shouldn't ever happen, and we'll want to see the full event
if it does somehow.
---
 plugins/eddn.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/plugins/eddn.py b/plugins/eddn.py
index d58eac26..2f54d609 100644
--- a/plugins/eddn.py
+++ b/plugins/eddn.py
@@ -1337,7 +1337,14 @@ def journal_entry(  # noqa: C901, CCR001
         elif this.systemaddress != entry.get('SystemAddress'):
             this.coordinates = None  # Docked event doesn't include coordinates
 
-        this.systemaddress = entry.get('SystemAddress')  # type: ignore
+        if 'SystemAddress' not in entry:
+            logger.warning(f'"location" event without SystemAddress !!!:\n{entry}\n')
+
+        # But we'll still *use* the value, because if a 'location' event doesn't
+        # have this we've still moved and now don't know where and MUST NOT
+        # continue to use any old value.
+        # Yes, explicitly state `None` here, so it's crystal clear.
+        this.systemaddress = entry.get('SystemAddress', None)  # type: ignore
 
     elif entry['event'] == 'ApproachBody':
         this.body_name = entry['Body']