细化异常

This commit is contained in:
2023-11-29 11:29:46 +08:00
parent 75a6989a7f
commit d59bccbd4d
4 changed files with 19 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ from nonebot_plugin_orm import get_session
from sqlalchemy import func, select from sqlalchemy import func, select
from ...db import query_bind_info from ...db import query_bind_info
from ...utils.exception import NeedCatchError from ...utils.exception import HandleNotFinishedError, NeedCatchError
from ...utils.metrics import get_metrics from ...utils.metrics import get_metrics
from ...utils.platform import get_platform from ...utils.platform import get_platform
from ...utils.typing import Me from ...utils.typing import Me
@@ -94,7 +94,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id())) await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id()))
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -118,7 +118,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me):
await matcher.send(message + await proc.handle_query()) await matcher.send(message + await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -132,7 +132,7 @@ async def _(event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_query()) await matcher.send(await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('rank') @alc.assign('rank')

View File

@@ -5,7 +5,7 @@ from nonebot_plugin_alconna import At, on_alconna
from nonebot_plugin_orm import get_session from nonebot_plugin_orm import get_session
from ...db import query_bind_info from ...db import query_bind_info
from ...utils.exception import NeedCatchError from ...utils.exception import HandleNotFinishedError, NeedCatchError
from ...utils.platform import get_platform from ...utils.platform import get_platform
from ...utils.typing import Me from ...utils.typing import Me
from .. import add_default_handlers from .. import add_default_handlers
@@ -77,7 +77,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id())) await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id()))
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -101,7 +101,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me):
await matcher.send(message + await proc.handle_query()) await matcher.send(message + await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -115,7 +115,7 @@ async def _(event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_query()) await matcher.send(await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
add_default_handlers(alc) add_default_handlers(alc)

View File

@@ -5,7 +5,7 @@ from nonebot_plugin_alconna import At, on_alconna
from nonebot_plugin_orm import get_session from nonebot_plugin_orm import get_session
from ...db import query_bind_info from ...db import query_bind_info
from ...utils.exception import NeedCatchError from ...utils.exception import HandleNotFinishedError, NeedCatchError
from ...utils.platform import get_platform from ...utils.platform import get_platform
from ...utils.typing import Me from ...utils.typing import Me
from .. import add_default_handlers from .. import add_default_handlers
@@ -87,7 +87,7 @@ try:
await matcher.send(await proc.handle_query()) await matcher.send(await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
except ImportError: except ImportError:
pass pass
@@ -103,7 +103,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id())) await matcher.send(await proc.handle_bind(platform=get_platform(bot), account=event.get_user_id()))
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -127,7 +127,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me):
await matcher.send(message + await proc.handle_query()) await matcher.send(message + await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
@alc.assign('query') @alc.assign('query')
@@ -141,7 +141,7 @@ async def _(event: Event, matcher: Matcher, account: User):
await matcher.send(await proc.handle_query()) await matcher.send(await proc.handle_query())
except NeedCatchError as e: except NeedCatchError as e:
await matcher.send(str(e)) await matcher.send(str(e))
raise raise HandleNotFinishedError from e
add_default_handlers(alc) add_default_handlers(alc)

View File

@@ -15,10 +15,6 @@ class NeedCatchError(TetrisStatsError):
"""需要被捕获的异常基类""" """需要被捕获的异常基类"""
class DoNotCatchError(TetrisStatsError):
"""不应该被捕获的异常基类"""
class RequestError(NeedCatchError): class RequestError(NeedCatchError):
"""请求错误""" """请求错误"""
@@ -27,9 +23,13 @@ class MessageFormatError(NeedCatchError):
"""用户发送的消息格式不正确""" """用户发送的消息格式不正确"""
class DatabaseVersionError(DoNotCatchError): class DoNotCatchError(TetrisStatsError):
"""数据库版本错误""" """不应该被捕获的异常基类"""
class WhatTheFuckError(DoNotCatchError): class WhatTheFuckError(DoNotCatchError):
"""用于表示不应该出现的情况 (""" """用于表示不应该出现的情况 ("""
class HandleNotFinishedError(DoNotCatchError):
"""任务没有正常完成处理的错误"""