Skip to content

Commit e399572

Browse files
committed
fix: reraise KeyboardInterrupt when excepting BaseException
1 parent 9216f2e commit e399572

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/pyfsd/metar/manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async def cache_metar(self) -> None:
157157
await logger.aerror(
158158
f"Metar fetcher {name} doesn't work because {err!s}"
159159
)
160-
except CancelledError:
160+
except (KeyboardInterrupt, CancelledError):
161161
raise
162162
# ruff: noqa: BLE001
163163
except BaseException:
@@ -215,7 +215,7 @@ async def fetch_once(
215215
metar = await fetcher(self.config, icao)
216216
if metar is not None:
217217
return metar
218-
except CancelledError:
218+
except (KeyboardInterrupt, CancelledError):
219219
raise
220220
except (VerifyKeyError, VerifyTypeError) as err:
221221
await logger.aerror(

src/pyfsd/plugin/manager.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ def deal_exception(name: str) -> None:
6767
"""Handle exceptions when importing plugins."""
6868
type_, exception, traceback = exc_info()
6969

70+
if exception is not None and type_ in (
71+
KeyboardInterrupt,
72+
CancelledError,
73+
):
74+
raise exception.with_traceback(traceback)
75+
7076
# Cut traceback to plugin file
7177
current_traceback = traceback
7278
while (
@@ -227,7 +233,7 @@ def setattr1(obj: object, name: str, val: object) -> None:
227233
try:
228234
if handlers := await plugin.setup():
229235
plugins_handlers[plugin] = handlers
230-
except CancelledError:
236+
except (KeyboardInterrupt, CancelledError):
231237
raise
232238
except BaseException:
233239
await logger.aexception(
@@ -293,7 +299,7 @@ async def trigger_event_handlers(
293299
handled_by_plugin=True,
294300
plugin=plugin,
295301
)
296-
except CancelledError:
302+
except (KeyboardInterrupt, CancelledError):
297303
raise
298304
except BaseException:
299305
await logger.aexception(
@@ -314,7 +320,7 @@ async def trigger_event_auditers(
314320
async def auditer_runner(auditer: Callable[..., Awaitable], name: str) -> None:
315321
try:
316322
await auditer(*args, **kwargs)
317-
except CancelledError:
323+
except (KeyboardInterrupt, CancelledError):
318324
raise
319325
except BaseException:
320326
await logger.aexception(f"Error happened when calling plugin {name}")

0 commit comments

Comments
 (0)