fix(gateway): replace print() with logger calls in BasePlatformAdapter (#3669)
Salvage of PR #3616 (memosr). Replaces 6 print() calls with proper logger calls in BasePlatformAdapter + removes redundant traceback.print_exc(). Co-Authored-By: memosr <memosr@users.noreply.github.com>
This commit is contained in:
@@ -1005,7 +1005,7 @@ class BasePlatformAdapter(ABC):
|
|||||||
# simultaneous messages. Queue them without interrupting the active run,
|
# simultaneous messages. Queue them without interrupting the active run,
|
||||||
# then process them immediately after the current task finishes.
|
# then process them immediately after the current task finishes.
|
||||||
if event.message_type == MessageType.PHOTO:
|
if event.message_type == MessageType.PHOTO:
|
||||||
print(f"[{self.name}] 🖼️ Queuing photo follow-up for session {session_key} without interrupt")
|
logger.debug("[%s] Queuing photo follow-up for session %s without interrupt", self.name, session_key)
|
||||||
existing = self._pending_messages.get(session_key)
|
existing = self._pending_messages.get(session_key)
|
||||||
if existing and existing.message_type == MessageType.PHOTO:
|
if existing and existing.message_type == MessageType.PHOTO:
|
||||||
existing.media_urls.extend(event.media_urls)
|
existing.media_urls.extend(event.media_urls)
|
||||||
@@ -1020,7 +1020,7 @@ class BasePlatformAdapter(ABC):
|
|||||||
return # Don't interrupt now - will run after current task completes
|
return # Don't interrupt now - will run after current task completes
|
||||||
|
|
||||||
# Default behavior for non-photo follow-ups: interrupt the running agent
|
# Default behavior for non-photo follow-ups: interrupt the running agent
|
||||||
print(f"[{self.name}] ⚡ New message while session {session_key} is active - triggering interrupt")
|
logger.debug("[%s] New message while session %s is active — triggering interrupt", self.name, session_key)
|
||||||
self._pending_messages[session_key] = event
|
self._pending_messages[session_key] = event
|
||||||
# Signal the interrupt (the processing task checks this)
|
# Signal the interrupt (the processing task checks this)
|
||||||
self._active_sessions[session_key].set()
|
self._active_sessions[session_key].set()
|
||||||
@@ -1206,9 +1206,9 @@ class BasePlatformAdapter(ABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not media_result.success:
|
if not media_result.success:
|
||||||
print(f"[{self.name}] Failed to send media ({ext}): {media_result.error}")
|
logger.warning("[%s] Failed to send media (%s): %s", self.name, ext, media_result.error)
|
||||||
except Exception as media_err:
|
except Exception as media_err:
|
||||||
print(f"[{self.name}] Error sending media: {media_err}")
|
logger.warning("[%s] Error sending media: %s", self.name, media_err)
|
||||||
|
|
||||||
# Send auto-detected local files as native attachments
|
# Send auto-detected local files as native attachments
|
||||||
for file_path in local_files:
|
for file_path in local_files:
|
||||||
@@ -1240,7 +1240,7 @@ class BasePlatformAdapter(ABC):
|
|||||||
# Check if there's a pending message that was queued during our processing
|
# Check if there's a pending message that was queued during our processing
|
||||||
if session_key in self._pending_messages:
|
if session_key in self._pending_messages:
|
||||||
pending_event = self._pending_messages.pop(session_key)
|
pending_event = self._pending_messages.pop(session_key)
|
||||||
print(f"[{self.name}] 📨 Processing queued message from interrupt")
|
logger.debug("[%s] Processing queued message from interrupt", self.name)
|
||||||
# Clean up current session before processing pending
|
# Clean up current session before processing pending
|
||||||
if session_key in self._active_sessions:
|
if session_key in self._active_sessions:
|
||||||
del self._active_sessions[session_key]
|
del self._active_sessions[session_key]
|
||||||
@@ -1254,9 +1254,7 @@ class BasePlatformAdapter(ABC):
|
|||||||
return # Already cleaned up
|
return # Already cleaned up
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[{self.name}] Error handling message: {e}")
|
logger.error("[%s] Error handling message: %s", self.name, e, exc_info=True)
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
# Send the error to the user so they aren't left with radio silence
|
# Send the error to the user so they aren't left with radio silence
|
||||||
try:
|
try:
|
||||||
error_type = type(e).__name__
|
error_type = type(e).__name__
|
||||||
|
|||||||
Reference in New Issue
Block a user