Skip to content

Commit c49dab9

Browse files
committed
CHANGES:
- RW: ignore_errors added to let other extensions run if RW errors out.
1 parent c12170d commit c49dab9

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

extensions/realweather/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ MyNode:
2525
# [...]
2626
extensions:
2727
RealWeather:
28-
enabled: true # optional to disable the extension, default: true
29-
debug: true # see outputs of RealWeather, default: false
28+
enabled: true # optional to disable the extension, default: true
29+
debug: true # see outputs of RealWeather, default: false
30+
ignore_errors: true # continue with other extensions like MizEdit, even if RW errors out
3031
metar:
3132
icao: URMM
3233
runway-elevation: 50

extensions/realweather/extension.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ def load_config(self) -> dict | None:
5858
with open(self.config_path, mode='rb') as infile:
5959
return tomli.load(infile)
6060
except Exception as ex:
61-
raise RealWeatherException(f"Error while reading {self.config_path}: {ex}")
61+
message = f"Error while reading {self.config_path}: {ex}"
62+
if self.config.get('ignore_errors', False):
63+
self.log.error(message)
64+
else:
65+
raise RealWeatherException(message)
6266

6367
def get_config(self, filename: str) -> dict:
6468
if 'terrains' in self.config:
@@ -116,7 +120,11 @@ async def generate_config_1_0(self, input_mission: str, output_mission: str, ove
116120
with open(self.config_path, mode='r', encoding='utf-8') as infile:
117121
cfg = json.load(infile)
118122
except json.JSONDecodeError as ex:
119-
raise RealWeatherException(f"Error while reading {self.config_path}: {ex}")
123+
message = f"Error while reading {self.config_path}: {ex}"
124+
if self.config.get('ignore_errors', False):
125+
self.log.error(message)
126+
else:
127+
raise RealWeatherException(message)
120128
config = await asyncio.to_thread(self.get_config, input_mission)
121129
# create proper configuration
122130
for name, element in cfg.items():
@@ -144,7 +152,12 @@ async def generate_config_2_0(self, input_mission: str, output_mission: str, ove
144152
with open(self.config_path, mode='rb') as infile:
145153
cfg = tomli.load(infile)
146154
except tomli.TOMLDecodeError as ex:
147-
raise RealWeatherException(f"Error while reading {self.config_path}: {ex}")
155+
message = f"Error while reading {self.config_path}: {ex}"
156+
if self.config.get('ignore_errors', False):
157+
self.log.error(message)
158+
else:
159+
raise RealWeatherException(message)
160+
148161
config = await asyncio.to_thread(self.get_config, input_mission)
149162
# create proper configuration
150163
for name, element in cfg.items():
@@ -213,8 +226,11 @@ def run_subprocess():
213226
stdout, stderr = process.communicate()
214227
if process.returncode != 0:
215228
error = stdout.decode('utf-8')
216-
self.log.error(error)
217-
raise RealWeatherException(f"Error during {self.name}: {process.returncode} - {error}")
229+
message = f"Error during {self.name}: {process.returncode} - {error}"
230+
if self.config.get('ignore_errors', False):
231+
self.log.error(message)
232+
else:
233+
raise RealWeatherException(message)
218234
output = stdout.decode('utf-8')
219235
metar = next((x for x in output.split('\n') if 'METAR:' in x), "")
220236
remarks = self.locals.get('realweather', {}).get('mission', {}).get('brief', {}).get('remarks', '')

extensions/realweather/schemas/realweather_schema.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ schema;node_realweather_schema:
66
name: {type: str, nullable: false, range: {min: 1}}
77
installation: {type: str, required: true, nullable: false, range: {min: 1}, func: dir_exists}
88
autoupdate: {type: bool, nullable: false}
9+
ignore_errors: {type: bool, nullable: false}
910
realweather:
1011
type: map
1112
nullable: false
@@ -84,6 +85,7 @@ schema;instance_realweather_schema:
8485
enabled: {type: bool, nullable: false}
8586
name: {type: str, nullable: false, range: {min: 1}}
8687
debug: {type: bool, nullable: false}
88+
ignore_errors: {type: bool, nullable: false}
8789
terrains:
8890
type: map
8991
nullable: false

0 commit comments

Comments
 (0)