Skip to content

Commit

Permalink
0171 - Fix crash on FSDJump in uncharted system (#173)
Browse files Browse the repository at this point in the history
Fixes #171 

* Fixed suspected flaw where we were trying to update from a key value that was empty.
* Added a test that showed the reported error and proves it's now fixed.
* Fixed the FSD jump by making sure even if we have system info in there, that we treat it as a jump and clear the hyperspace tag.
* Fixed a crash (by adding a precaution) - added a try-catch around the calls from the background watcher so it can't just die and leave the UI + logs unresponsive.
  • Loading branch information
joncage authored Mar 13, 2021
1 parent 88dae59 commit a11b4e9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
3 changes: 1 addition & 2 deletions EDScoutCore/EDScout.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def append_info_to_fsdjump(self, new_entry):
new_entry["StarClass"] = self.lookup_star_class(new_entry)

edsm_report = EDScout.get_edsm_system_report(new_entry['StarSystem'], 'FSDJump')
new_entry["valuableBodies"] = edsm_report["valuableBodies"]
new_entry["estimatedValueMapped"] = edsm_report["estimatedValueMapped"]
new_entry.update(edsm_report)

return new_entry

Expand Down
7 changes: 6 additions & 1 deletion EDScoutCore/JournalInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ def trigger_current_journal_check(self):

def _on_journal_change(self, altered_file):
self.set_current_journal(altered_file) # Make sure we keep the prompter pointed at the current file.
self.report_journal_change(altered_file)
try:
self.report_journal_change(altered_file)
except Exception as e:
# Capture and report.
# Hopefully this will prevent the background watcher from going down permanently.
logger.exception(e)

def _configure_watchers(self):
if not os.path.exists(self.journal_path):
Expand Down
37 changes: 30 additions & 7 deletions EDScoutCore/test_EdScout.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ def setup_method(self, test_data):
self.new_entry = []
# { "timestamp":"2020-08-20T23:57:05Z", "event":"Scan", "ScanType":"Detailed", "BodyName":"Pro Eurl MO-H d10-11 2", "BodyID":27, "Parents":[ {"Star":0} ], "StarSystem":"Pro Eurl MO-H d10-11", "SystemAddress":388770122203, "DistanceFromArrivalLS":5502.835374, "TidalLock":false, "TerraformState":"", "PlanetClass":"Sudarsky class III gas giant", "Atmosphere":"", "AtmosphereComposition":[ { "Name":"Hydrogen", "Percent":74.636978 }, { "Name":"Helium", "Percent":25.363026 } ], "Volcanism":"", "MassEM":1115.081787, "Radius":76789080.000000, "SurfaceGravity":75.373241, "SurfaceTemperature":272.228607, "SurfacePressure":0.000000, "Landable":false, "SemiMajorAxis":1634133458137.512207, "Eccentricity":0.018997, "OrbitalInclination":-4.741432, "Periapsis":30.585864, "OrbitalPeriod":1122406125.068665, "RotationPeriod":113532.553386, "AxialTilt":-0.182964, "Rings":[ { "Name":"Pro Eurl MO-H d10-11 2 A Ring", "RingClass":"eRingClass_MetalRich", "MassMT":1.8852e+12, "InnerRad":1.1586e+08, "OuterRad":3.61e+08 } ], "ReserveLevel":"PristineResources", "WasDiscovered":false, "WasMapped":false }

self.scout = EDScout(journal_watcher=DummyWatcher(), journal_change_processor=DummyJournalChangeProcessor())
self.scout.report_new_info = self.mock_report_new_info


def mock_report_new_info(self, new_entry):
self.new_entry.append(new_entry)

def test_process_scan_entry(self):
# ARRANGE
# Input data
new_entry = {"timestamp": "2020-08-20T23: 56: 51Z",
"event": "Scan",
Expand All @@ -81,18 +86,36 @@ def test_process_scan_entry(self):
"WasDiscovered": False,
"WasMapped": False}

# ARRANGE
scout = EDScout(journal_watcher=DummyWatcher(), journal_change_processor=DummyJournalChangeProcessor())
scout.report_new_info = self.mock_report_new_info

# ACT
scout.process_journal_change(new_entry)
self.scout.process_journal_change(new_entry)

# ASSERT
assert len(self.new_entry) == 1, "There should be one report for the FSD target command then another for the " \
"system report"
assert len(self.new_entry) == 1, "There should only be a single report for a Scan event as we should have all" \
" the required info "
reported_entry = self.new_entry[0]
assert reported_entry is not None
assert 'MappedValue' in reported_entry
assert 'BodyName' in reported_entry
assert 'StarSystem' in reported_entry

def test_unmapped_scan_entry(self):
# ARRANGE
# Input data (simulate issue #171 by showing a jump to a system that defintiely does not exist)
input_data = {"timestamp": "2020-07-17T21:50:36Z", "event": "FSDJump", "StarSystem": "Flibble Flibble",
"SystemAddress": 123456789, "StarPos": [-49.87500, 317.75000, -0.56250], "SystemAllegiance": "",
"SystemEconomy": "$economy_None;", "SystemEconomy_Localised": "None", "SystemSecondEconomy": "$economy_None;",
"SystemSecondEconomy_Localised": "None", "SystemGovernment": "$government_None;",
"SystemGovernment_Localised": "None", "SystemSecurity": "$GAlAXY_MAP_INFO_state_anarchy;",
"SystemSecurity_Localised": "Anarchy", "Population": 0, "Body": "HIP 64420", "BodyID": 0, "BodyType": "Star",
"JumpDist": 12.219, "FuelUsed": 0.947167, "FuelLevel": 12.835925}

# ACT
self.scout.process_journal_change(input_data)

# ASSERT
assert len(self.new_entry) == 2, "There should be one report for the FSD target command then another for the " \
"system report: "+str(self.new_entry)
reported_entry = self.new_entry[0]
assert reported_entry is not None
assert 'Body' in reported_entry
assert 'StarSystem' in reported_entry
8 changes: 6 additions & 2 deletions EDScoutWebUI/static/EdScout.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,15 @@
addNewSystemToContainer(payloadContent, container);
}
}
else if ((payloadContent.type === 'System-Location') || // Update the system recorded in 'current system'
(payloadContent.type === 'System-FSDJump')) // Happens at the end of the jump so update the current system.
else if (payloadContent.type === 'System-Location')
{
addNewSystemToContainer(payloadContent, document.getElementById('location'));
}
else if (payloadContent.type === 'System-FSDJump') // Happens at the end of the jump so update the current system.
{
finishJump(payloadContent);
addNewSystemToContainer(payloadContent, document.getElementById('location'));
}


}
Expand Down

0 comments on commit a11b4e9

Please sign in to comment.