Skip to content

Commit

Permalink
fix: 热重载失败后正确fallback到登录流程
Browse files Browse the repository at this point in the history
  • Loading branch information
z2z63 committed Aug 11, 2024
1 parent dc4f684 commit fd56976
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "VChat"
version = "1.0.1"
dynamic = ["version"]
authors = [
{ name="z2z63", email="vituralfuture@gmail.com" },
]
Expand All @@ -26,5 +26,8 @@ Homepage = "https://github.com/z2z63/VChat"
Issues = "https://github.com/z2z63/VChat/issues"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "vchat/_version.py"
1 change: 1 addition & 0 deletions vchat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_version.py
1 change: 0 additions & 1 deletion vchat/core/hotreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async def _load_login_status(self, file_path, login_callback=None):
rmsgs, contacts = await self._net_helper.get_msg()
except VOperationFailedError:
await self.logout()
await self._load_last_login_status(jar["cookies"])
logger.debug("server refused, loading login status failed.")
raise VNetworkError("server refused, loading login status failed.")

Expand Down
20 changes: 8 additions & 12 deletions vchat/net/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


def catch_exception(
fn: Callable[P, Coroutine[Any, Any, T]]
fn: Callable[P, Coroutine[Any, Any, T]]
) -> Callable[P, Coroutine[Any, Any, T]]:
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
try:
Expand All @@ -33,11 +33,7 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
msg = f"{fn.__name__}出现网络错误: {str(e)}"
logger.warning(msg)
raise VNetworkError(msg)
except KeyError as e:
msg = f"服务器返回的数据错误: {str(e)}"
logger.warning(msg)
raise VOperationFailedError(msg)
except AttributeError as e:
except (KeyError, AttributeError, ValueError) as e:
msg = f"服务器返回的数据错误: {str(e)}"
logger.warning(msg)
raise VOperationFailedError(msg)
Expand Down Expand Up @@ -97,7 +93,7 @@ async def show_mobile_login(self):

@abstractmethod
async def update_batch_contact(
self, batch: int, callback: Callable
self, batch: int, callback: Callable
) -> tuple[Literal[0, 1], Iterable[Contact]]:
pass

Expand All @@ -108,7 +104,7 @@ async def update_chatroom(self, usernames: list[str]) -> list[dict]:

@abstractmethod
async def get_detailed_member_info(
self, encry_chatroom_id: str, members: Collection[User]
self, encry_chatroom_id: str, members: Collection[User]
) -> AsyncGenerator[User, None]:
async for member in self.get_detailed_member_info(encry_chatroom_id, members):
yield member
Expand Down Expand Up @@ -140,7 +136,7 @@ async def get_chatroom_head_img(self, chatroom_name: str, fd: BinaryIO) -> None:

@abstractmethod
async def get_chatroom_member_head_img(
self, username: str, chatroom_id: str, fd: BinaryIO
self, username: str, chatroom_id: str, fd: BinaryIO
) -> None:
pass

Expand All @@ -154,7 +150,7 @@ async def set_chatroom_name(self, chatroom_username, name):

@abstractmethod
async def delete_member_from_chatroom(
self, chatroom_username: str, members: list[User]
self, chatroom_username: str, members: list[User]
):
pass

Expand Down Expand Up @@ -196,7 +192,7 @@ def get_dumpable_cookies(self):

@abstractmethod
def _get_download_fn(
self, url: str, params: dict, headers: dict | None = None
self, url: str, params: dict, headers: dict | None = None
) -> Callable[..., Awaitable]:
pass

Expand All @@ -218,7 +214,7 @@ def get_attach_download_fn(self, rmsg: "RawMessage|dict[str, str]"):

@abstractmethod
async def send_document(
self, file_name: str, media_id: str, file_size: int, to_username: str
self, file_name: str, media_id: str, file_size: int, to_username: str
) -> None:
pass

Expand Down

0 comments on commit fd56976

Please sign in to comment.