Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions python/dify_plugin/core/trigger_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ def get_subscription_constructor_cls(self, provider_name: str) -> type[TriggerSu
# ------------------------------------------------------------------

def get_trigger_event_handler_safely(self, provider_name: str, event: str, runtime: EventRuntime) -> Event | None:
entry = self._get_entry(provider_name)
if event not in entry.events:
try:
entry = self._get_entry(provider_name)
if event not in entry.events:
return None
_, event_cls = entry.events[event]
return event_cls(runtime)
except Exception as e:
print(f"Error getting trigger event handler: {e!s}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using print() for errors in a library is not a best practice. It's better to use the logging module. This allows developers using your library to configure how and where logs are handled (e.g., setting log levels, redirecting to a file or a logging service), which is much more flexible than printing to standard output.

You'll need to add import logging at the top of the file.

As a side note, catching a broad Exception is powerful for a 'safe' function like this, but it can sometimes mask unexpected issues. It's worth being aware of this trade-off.

Suggested change
print(f"Error getting trigger event handler: {e!s}")
logging.warning(f"Error getting trigger event handler: {e!s}")

return None
_, event_cls = entry.events[event]
return event_cls(runtime)

def get_trigger_event_handler(self, provider_name: str, event: str, runtime: EventRuntime) -> Event:
"""Instantiate an event for the given provider and event name."""
Expand Down