Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit c7bbcf0

Browse files
committed
logging: add more logging for when event handlers raise exceptions
1 parent 1923c0b commit c7bbcf0

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# v0.4.2rc1
1+
# v0.4.2rc2
22

33
* Explicitly specify the timeout of each event stream connection to help avoid
44
weird states where the event stream is open but not receiving events.
5+
* Add more logging and error handling when event listener handlers fail.
56

67
# v0.4.1
78

linkedin_messaging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .api_objects import URN
33

44
__title__ = "linkedin_messaging"
5-
__version__ = "0.4.2rc1"
5+
__version__ = "0.4.2rc2"
66
__description__ = "An unofficial API for interacting with LinkedIn Messaging"
77

88
__license__ = "MIT"

linkedin_messaging/linkedin.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ def add_event_listener(
515515

516516
async def _fire(self, payload_key: str, event: Any):
517517
for listener in self.event_listeners[payload_key]:
518-
await listener(event)
518+
try:
519+
await listener(event)
520+
except Exception:
521+
logging.exception(f"Listener {listener} failed to handle {event}")
519522

520523
async def _listen_to_event_stream(self):
521524
logging.info("Starting event stream listener")
@@ -543,7 +546,12 @@ async def _listen_to_event_stream(self):
543546
# Special handling for ALL_EVENTS handler.
544547
if all_events_handlers := self.event_listeners.get("ALL_EVENTS"):
545548
for handler in all_events_handlers:
546-
await handler(data)
549+
try:
550+
await handler(data)
551+
except Exception:
552+
logging.exception(
553+
f"Handler {handler} failed to handle {data}"
554+
)
547555

548556
event_payload = data.get(
549557
"com.linkedin.realtimefrontend.DecoratedEvent", {}
@@ -565,16 +573,20 @@ async def start_listener(self):
565573
# Special handling for TIMEOUT handler.
566574
if all_events_handlers := self.event_listeners.get("TIMEOUT"):
567575
for handler in all_events_handlers:
568-
await handler(te)
569-
await asyncio.sleep(1)
570-
continue
576+
try:
577+
await handler(te)
578+
except Exception:
579+
logging.exception(
580+
f"Handler {handler} failed to handle {te}"
581+
)
571582
except Exception as e:
572583
logging.exception(f"Error listening to event stream: {e}")
573584
# Special handling for STREAM_ERROR handler.
574585
if all_events_handlers := self.event_listeners.get("STREAM_ERROR"):
575586
for handler in all_events_handlers:
576-
await handler(e)
577-
await asyncio.sleep(1)
578-
continue
587+
try:
588+
await handler(e)
589+
except Exception:
590+
logging.exception(f"Handler {handler} failed to handle {e}")
579591

580592
# endregion

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "linkedin_messaging"
3-
version = "0.4.2rc1"
3+
version = "0.4.2rc2"
44
description = "An unofficial API for interacting with LinkedIn Messaging"
55
authors = ["Sumner Evans <inquiries@sumnerevans.com>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)