From 98be18292295b181bff157b2eb607102d151bb47 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 17:03:39 +0000 Subject: [PATCH 1/2] plugins/eddn: Add paranoia about data in is_horizons() A damaged station has `"modules": []`, so trips over modules.values(). --- plugins/eddn.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 29de4910..6533f638 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -789,8 +789,18 @@ MAP_STR_ANY = Mapping[str, Any] def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY) -> bool: - return ( - any(economy['name'] == 'Colony' for economy in economies.values()) or - any(module.get('sku') == HORIZ_SKU for module in modules.values()) or - any(ship.get('sku') == HORIZ_SKU for ship in (ships['shipyard_list'] or {}).values()) - ) + economies_colony = False + modules_horizons = False + ship_horizons = False + + if isinstance(dict, economies): + economies_colony = any(economy['name'] == 'Colony' for economy in economies.values()) + + if isinstance(dict, modules): + modules_horizons = any(module.get('sku') == HORIZ_SKU for module in modules.values()) + + if isinstance(dict, ships): + if ships.get('shipyard_list') is not None: + ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + + return economies_colony or modules_horizons or ship_horizons From 173cffdcfc8f225c7172b9ba01a2851896e5c81d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 17:06:26 +0000 Subject: [PATCH 2/2] Add extra logging to is_horizons() if things not as expected. * Log the type(s) if not dict. * Log if ships['shipyard_list'] isn't present, despite ships being a dict. --- plugins/eddn.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index 6533f638..12f2b207 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -796,11 +796,23 @@ def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY if isinstance(dict, economies): economies_colony = any(economy['name'] == 'Colony' for economy in economies.values()) + else: + logger.error(f'economies type is {type(economies)}') + if isinstance(dict, modules): modules_horizons = any(module.get('sku') == HORIZ_SKU for module in modules.values()) + else: + logger.error(f'modules type is {type(modules)}') + if isinstance(dict, ships): if ships.get('shipyard_list') is not None: ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + else: + logger.debug('No ships["shipyard_list"] - Damaged station or FC ?') + + else: + logger.error(f'ships type is {type(ships)}') + return economies_colony or modules_horizons or ship_horizons