fix: use loguru native formatting to prevent KeyError on messages containing curly braces

Closes #857
This commit is contained in:
Nikolas de Hor
2026-02-19 17:19:36 -03:00
parent d22929305f
commit 53b83a38e2
18 changed files with 80 additions and 80 deletions

View File

@@ -156,7 +156,7 @@ class FeishuChannel(BaseChannel):
try:
self._ws_client.start()
except Exception as e:
logger.warning(f"Feishu WebSocket error: {e}")
logger.warning("Feishu WebSocket error: {}", e)
if self._running:
import time; time.sleep(5)
@@ -177,7 +177,7 @@ class FeishuChannel(BaseChannel):
try:
self._ws_client.stop()
except Exception as e:
logger.warning(f"Error stopping WebSocket client: {e}")
logger.warning("Error stopping WebSocket client: {}", e)
logger.info("Feishu bot stopped")
def _add_reaction_sync(self, message_id: str, emoji_type: str) -> None:
@@ -194,11 +194,11 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message_reaction.create(request)
if not response.success():
logger.warning(f"Failed to add reaction: code={response.code}, msg={response.msg}")
logger.warning("Failed to add reaction: code={}, msg={}", response.code, response.msg)
else:
logger.debug(f"Added {emoji_type} reaction to message {message_id}")
except Exception as e:
logger.warning(f"Error adding reaction: {e}")
logger.warning("Error adding reaction: {}", e)
async def _add_reaction(self, message_id: str, emoji_type: str = "THUMBSUP") -> None:
"""
@@ -312,10 +312,10 @@ class FeishuChannel(BaseChannel):
logger.debug(f"Uploaded image {os.path.basename(file_path)}: {image_key}")
return image_key
else:
logger.error(f"Failed to upload image: code={response.code}, msg={response.msg}")
logger.error("Failed to upload image: code={}, msg={}", response.code, response.msg)
return None
except Exception as e:
logger.error(f"Error uploading image {file_path}: {e}")
logger.error("Error uploading image {}: {}", file_path, e)
return None
def _upload_file_sync(self, file_path: str) -> str | None:
@@ -339,10 +339,10 @@ class FeishuChannel(BaseChannel):
logger.debug(f"Uploaded file {file_name}: {file_key}")
return file_key
else:
logger.error(f"Failed to upload file: code={response.code}, msg={response.msg}")
logger.error("Failed to upload file: code={}, msg={}", response.code, response.msg)
return None
except Exception as e:
logger.error(f"Error uploading file {file_path}: {e}")
logger.error("Error uploading file {}: {}", file_path, e)
return None
def _send_message_sync(self, receive_id_type: str, receive_id: str, msg_type: str, content: str) -> bool:
@@ -360,14 +360,14 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message.create(request)
if not response.success():
logger.error(
f"Failed to send Feishu {msg_type} message: code={response.code}, "
f"msg={response.msg}, log_id={response.get_log_id()}"
"Failed to send Feishu {} message: code={}, msg={}, log_id={}",
msg_type, response.code, response.msg, response.get_log_id()
)
return False
logger.debug(f"Feishu {msg_type} message sent to {receive_id}")
return True
except Exception as e:
logger.error(f"Error sending Feishu {msg_type} message: {e}")
logger.error("Error sending Feishu {} message: {}", msg_type, e)
return False
async def send(self, msg: OutboundMessage) -> None:
@@ -409,7 +409,7 @@ class FeishuChannel(BaseChannel):
)
except Exception as e:
logger.error(f"Error sending Feishu message: {e}")
logger.error("Error sending Feishu message: {}", e)
def _on_message_sync(self, data: "P2ImMessageReceiveV1") -> None:
"""
@@ -481,4 +481,4 @@ class FeishuChannel(BaseChannel):
)
except Exception as e:
logger.error(f"Error processing Feishu message: {e}")
logger.error("Error processing Feishu message: {}", e)