Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 修复异常在 traceback 中无法正常显示信息 #1521

Merged
merged 1 commit into from
Dec 31, 2022
Merged
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
18 changes: 3 additions & 15 deletions nonebot/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
class NoneBotException(Exception):
"""所有 NoneBot 发生的异常基类。"""

def __str__(self) -> str:
return self.__repr__()


# Rule Exception
class ParserExit(NoneBotException):
Expand All @@ -53,9 +56,6 @@ def __repr__(self) -> str:
+ ")"
)

def __str__(self) -> str:
return self.__repr__()


# Processor Exception
class ProcessException(NoneBotException):
Expand All @@ -75,9 +75,6 @@ def __init__(self, reason: Any):
def __repr__(self) -> str:
return f"IgnoredException(reason={self.reason!r})"

def __str__(self) -> str:
return self.__repr__()


class SkippedException(ProcessException):
"""指示 NoneBot 立即结束当前 `Dependent` 的运行。
Expand Down Expand Up @@ -109,9 +106,6 @@ def __repr__(self) -> str:
f"type={self.param._type_display()}, value={self.value!r}>"
)

def __str__(self) -> str:
return self.__repr__()


class MockApiException(ProcessException):
"""指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。可由 api hook 抛出。
Expand All @@ -126,9 +120,6 @@ def __init__(self, result: Any):
def __repr__(self) -> str:
return f"MockApiException(result={self.result!r})"

def __str__(self) -> str:
return self.__repr__()


class StopPropagation(ProcessException):
"""指示 NoneBot 终止事件向下层传播。
Expand Down Expand Up @@ -244,6 +235,3 @@ def __repr__(self) -> str:
+ (f", reason={self.reason!r}" if self.reason else "")
+ ")"
)

def __str__(self) -> str:
return self.__repr__()