Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/Language/obtain_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self):
value = self._read_language_value()
self.finished.emit(value)
except Exception as e:
logger.error(f"读取语言内容失败: {e}")
logger.exception(f"读取语言内容失败: {e}")
self.finished.emit(None)

def _read_language_value(self):
Expand Down
10 changes: 5 additions & 5 deletions app/common/IPC_URL/csharp_ipc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def start_ipc_client(self) -> bool:
return True
except Exception as e:
self.is_running = False
logger.error(f"启动 C# IPC 客户端失败: {e}")
logger.exception(f"启动 C# IPC 客户端失败: {e}")
return False

def stop_ipc_client(self):
Expand Down Expand Up @@ -195,7 +195,7 @@ def get_on_class_left_time(self) -> int:

return total_seconds
except Exception as e:
logger.error(f"获取距离上课时间失败: {e}")
logger.exception(f"获取距离上课时间失败: {e}")
return 0

def get_current_class_info(self) -> dict:
Expand Down Expand Up @@ -230,7 +230,7 @@ def get_current_class_info(self) -> dict:
return {"name": class_name}

except Exception as e:
logger.error(f"从 ClassIsland 获取课程信息失败: {e}")
logger.exception(f"从 ClassIsland 获取课程信息失败: {e}")
return {}

def get_next_class_info(self) -> dict:
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_next_class_info(self) -> dict:
return {"name": class_name}

except Exception as e:
logger.error(f"从 ClassIsland 获取下一节课信息失败: {e}")
logger.exception(f"从 ClassIsland 获取下一节课信息失败: {e}")
return {}

@staticmethod
Expand Down Expand Up @@ -335,7 +335,7 @@ async def client():
except asyncio.CancelledError:
pass
except Exception as e:
logger.error(f"C# IPC 客户端循环出错: {e}")
logger.exception(f"C# IPC 客户端循环出错: {e}")
finally:
self.loop.close()
self.loop = None
Expand Down
16 changes: 8 additions & 8 deletions app/common/IPC_URL/protocol_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def register_protocol(self) -> bool:
elif self.is_linux:
return self._register_linux_protocol()
else:
logger.error(f"不支持的操作系统: {sys.platform}")
logger.exception(f"不支持的操作系统: {sys.platform}")
return False

def unregister_protocol(self) -> bool:
Expand All @@ -54,7 +54,7 @@ def unregister_protocol(self) -> bool:
elif self.is_linux:
return self._unregister_linux_protocol()
else:
logger.error(f"不支持的操作系统: {sys.platform}")
logger.exception(f"不支持的操作系统: {sys.platform}")
return False

def is_protocol_registered(self) -> bool:
Expand All @@ -81,7 +81,7 @@ def _register_windows_protocol(self) -> bool:
return self._register_windows_protocol_current_user(exe_path)

except Exception as e:
logger.error(f"Windows协议注册失败: {e}")
logger.exception(f"Windows协议注册失败: {e}")
return False

def _register_windows_protocol_current_user(self, exe_path: str) -> bool:
Expand All @@ -105,7 +105,7 @@ def _register_windows_protocol_current_user(self, exe_path: str) -> bool:
return True

except Exception as e:
logger.error(f"Windows当前用户协议注册失败: {e}")
logger.exception(f"Windows当前用户协议注册失败: {e}")
return False

def _unregister_windows_protocol(self) -> bool:
Expand All @@ -115,7 +115,7 @@ def _unregister_windows_protocol(self) -> bool:
return self._unregister_windows_protocol_current_user()

except Exception as e:
logger.error(f"Windows协议注销失败: {e}")
logger.exception(f"Windows协议注销失败: {e}")
return False

def _unregister_windows_protocol_current_user(self) -> bool:
Expand All @@ -138,7 +138,7 @@ def _unregister_windows_protocol_current_user(self) -> bool:
return True

except Exception as e:
logger.error(f"Windows当前用户协议注销失败: {e}")
logger.exception(f"Windows当前用户协议注销失败: {e}")
return False

def _is_windows_protocol_registered(self) -> bool:
Expand Down Expand Up @@ -177,7 +177,7 @@ def _register_linux_protocol(self) -> bool:
return True

except Exception as e:
logger.error(f"Linux协议注册失败: {e}")
logger.exception(f"Linux协议注册失败: {e}")
return False

def _unregister_linux_protocol(self) -> bool:
Expand All @@ -194,7 +194,7 @@ def _unregister_linux_protocol(self) -> bool:
return True

except Exception as e:
logger.error(f"Linux协议注销失败: {e}")
logger.exception(f"Linux协议注销失败: {e}")
return False

def _is_linux_protocol_registered(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions app/common/IPC_URL/security_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def verify(self, verification_data: Dict[str, Any]) -> bool:
return result

except Exception as e:
logger.error(f"验证过程出错: {e}")
logger.exception(f"验证过程出错: {e}")
return False

def _check_attempt_limit(self, command: str) -> bool:
Expand Down Expand Up @@ -451,7 +451,7 @@ def _perform_verification(
result = verifier.verify(verification_data)
results.append(result)
except Exception as e:
logger.error(f"验证器执行失败: {e}")
logger.exception(f"验证器执行失败: {e}")
results.append(False)

if self.require_all:
Expand Down
14 changes: 7 additions & 7 deletions app/common/IPC_URL/url_command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def handle_url_command(
return result

except Exception as e:
logger.error(f"URL命令处理失败: {e}")
logger.exception(f"URL命令处理失败: {e}")
return {
"status": "error",
"message": f"命令处理失败: {str(e)}",
Expand Down Expand Up @@ -163,7 +163,7 @@ def handle_ipc_command(self, message: Dict[str, Any]) -> Dict[str, Any]:
}

except Exception as e:
logger.error(f"IPC命令处理失败: {e}")
logger.exception(f"IPC命令处理失败: {e}")
return {"status": "error", "message": f"IPC命令处理失败: {str(e)}"}

def _parse_url(self, url: str) -> tuple:
Expand Down Expand Up @@ -318,7 +318,7 @@ def execute_command():
logger.debug(f"验证后执行命令完成: {command}, 结果: {result}")
return result
except Exception as e:
logger.error(f"验证后执行命令失败: {command}, 错误: {e}")
logger.exception(f"验证后执行命令失败: {command}, 错误: {e}")

# 调用验证窗口
create_verify_password_window(on_verified=execute_command, operation_type=op)
Expand All @@ -345,7 +345,7 @@ def _execute_command(self, command: str, params: Dict[str, Any]) -> Dict[str, An
logger.debug(f"命令执行成功: {command}, 结果: {result}")
return result
except Exception as e:
logger.error(f"命令执行失败: {command}, 错误: {e}")
logger.exception(f"命令执行失败: {command}, 错误: {e}")
return {
"status": "error",
"message": f"命令执行失败: {str(e)}",
Expand All @@ -365,7 +365,7 @@ def _execute_command(self, command: str, params: Dict[str, Any]) -> Dict[str, An
)
return result
except Exception as e:
logger.error(
logger.exception(
f"模糊匹配命令执行失败: {matched_command}, 错误: {e}"
)
return {
Expand All @@ -383,7 +383,7 @@ def _execute_command(self, command: str, params: Dict[str, Any]) -> Dict[str, An
}

except Exception as e:
logger.error(f"命令执行失败: {e}")
logger.exception(f"命令执行失败: {e}")
return {
"status": "error",
"message": f"命令执行失败: {str(e)}",
Expand Down Expand Up @@ -724,7 +724,7 @@ def verify_and_execute(
)

if not self.security_verifier:
logger.error("安全验证器未配置")
logger.exception("安全验证器未配置")
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

Using logger.exception() outside of an exception handler will cause an error. This code is not within a try-except block, so calling logger.exception() when self.security_verifier is None/False will fail because there's no active exception to log. This should remain as logger.error() since it's a configuration issue, not an exception being caught.

Suggested change
logger.exception("安全验证器未配置")
logger.error("安全验证器未配置")

Copilot uses AI. Check for mistakes.
return {"success": False, "error": "安全验证器未配置"}

# 执行安全验证
Expand Down
24 changes: 12 additions & 12 deletions app/common/IPC_URL/url_ipc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def register_url_protocol(self) -> bool:
try:
return self.protocol_manager.register_protocol()
except Exception as e:
logger.error(f"注册URL协议失败: {e}")
logger.exception(f"注册URL协议失败: {e}")
return False

def unregister_url_protocol(self) -> bool:
Expand All @@ -65,7 +65,7 @@ def unregister_url_protocol(self) -> bool:
try:
return self.protocol_manager.unregister_protocol()
except Exception as e:
logger.error(f"注销URL协议失败: {e}")
logger.exception(f"注销URL协议失败: {e}")
return False

def is_protocol_registered(self) -> bool:
Expand Down Expand Up @@ -97,7 +97,7 @@ def start_ipc_server(self, port: int = 0) -> bool:
self.is_running = True
return True
except Exception as e:
logger.error(f"启动IPC服务器失败: {e}")
logger.exception(f"启动IPC服务器失败: {e}")
return False

def stop_ipc_server(self):
Expand Down Expand Up @@ -140,11 +140,11 @@ def _run_server(self, port: int):
continue
except Exception as e:
if self.is_running:
logger.error(f"IPC服务器错误: {e}")
logger.exception(f"IPC服务器错误: {e}")
break

except Exception as e:
logger.error(f"IPC服务器启动错误: {e}")
logger.exception(f"IPC服务器启动错误: {e}")
finally:
if "server_socket" in locals():
server_socket.close()
Expand All @@ -158,7 +158,7 @@ def _handle_client(self, client_socket: socket.socket, address: tuple):
response = self._process_message(message)
client_socket.send(json.dumps(response).encode("utf-8"))
except Exception as e:
logger.error(f"处理IPC消息错误: {e}")
logger.exception(f"处理IPC消息错误: {e}")
finally:
client_socket.close()

Expand Down Expand Up @@ -188,7 +188,7 @@ def _process_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
"type": message_type,
"error": str(e),
}
logger.error(f"消息处理失败 - 类型: {message_type}, 错误: {e}")
logger.exception(f"消息处理失败 - 类型: {message_type}, 错误: {e}")
return error_response
else:
unknown_response = {
Expand Down Expand Up @@ -224,7 +224,7 @@ def _handle_url_message(self, payload: Dict[str, Any]) -> Dict[str, Any]:
logger.info(f"URL命令执行成功: {url}, 结果: {result}")
return {"success": True, "result": result}
except Exception as e:
logger.error(f"URL命令执行失败: {url}, 错误: {e}")
logger.exception(f"URL命令执行失败: {url}, 错误: {e}")
return {"success": False, "error": str(e)}

def register_message_handler(self, message_type: str, handler: Callable):
Expand Down Expand Up @@ -262,7 +262,7 @@ def send_ipc_message(
return json.loads(response_data)

except Exception as e:
logger.error(f"发送IPC消息失败: {e}")
logger.exception(f"发送IPC消息失败: {e}")
return None

def _save_port_config(self, port: int):
Expand All @@ -286,7 +286,7 @@ def load_port_config(self) -> Optional[int]:
config = json.load(f)
return config.get("port")
except Exception as e:
logger.error(f"加载端口配置失败: {e}")
logger.exception(f"加载端口配置失败: {e}")

return None

Expand Down Expand Up @@ -328,7 +328,7 @@ def handle_url_args(self, url: str) -> Dict[str, Any]:
return result

except Exception as e:
logger.error(f"URL参数解析失败: {url}, 错误: {e}")
logger.exception(f"URL参数解析失败: {url}, 错误: {e}")
return {"success": False, "error": str(e)}

def execute_url_command(
Expand Down Expand Up @@ -361,7 +361,7 @@ def execute_url_command(
logger.info(f"URL命令执行成功: {url}, 结果: {result}")
return {"success": True, "result": result}
except Exception as e:
logger.error(f"URL命令执行失败: {url}, 错误: {e}")
logger.exception(f"URL命令执行失败: {url}, 错误: {e}")
return {"success": False, "error": str(e)}

def get_available_commands(self) -> Dict[str, Any]:
Expand Down
10 changes: 5 additions & 5 deletions app/common/behind_scenes/behind_scenes_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_behind_scenes_settings(use_cache=True):
BehindScenesUtils._cache_timestamp = current_time
return settings
except Exception as e:
logger.error(f"读取内幕设置失败: {e}")
logger.exception(f"读取内幕设置失败: {e}")
return {}

@staticmethod
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_probability_settings(name, mode, pool_name=None):
return {"enabled": False, "probability": 1.0}
return {"enabled": False, "probability": 1.0}
except Exception as e:
logger.error(f"获取概率设置失败: {e}")
logger.exception(f"获取概率设置失败: {e}")
return {"enabled": False, "probability": 1.0}

@staticmethod
Expand Down Expand Up @@ -176,7 +176,7 @@ def apply_probability_weights(

return filtered_students, weights
except Exception as e:
logger.error(f"应用内幕设置失败: {e}")
logger.exception(f"应用内幕设置失败: {e}")
return students_dict_list, [1.0] * len(students_dict_list)

@staticmethod
Expand Down Expand Up @@ -239,7 +239,7 @@ def apply_probability_weights_to_items(items, mode, pool_name):

return filtered_items, weights
except Exception as e:
logger.error(f"应用内幕设置失败: {e}")
logger.exception(f"应用内幕设置失败: {e}")
return items, [1.0] * len(items)

@staticmethod
Expand Down Expand Up @@ -271,5 +271,5 @@ def ensure_guaranteed_selection(

return None
except Exception as e:
logger.error(f"确保必中人员失败: {e}")
logger.exception(f"确保必中人员失败: {e}")
return None
Loading
Loading