From a12cefbffc8fe875d99765e8c814773da157b858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 31 Jul 2024 13:44:50 +0800 Subject: [PATCH] Remove traceback, raise instead --- modules/bilibili/bili_api.py | 5 +---- modules/bugtracker/bugtracker.py | 3 +-- modules/cytoid/profile.py | 5 +---- modules/github/repo.py | 19 ++++++------------- modules/github/user.py | 5 +---- modules/osu/profile.py | 3 +-- modules/tweet/__init__.py | 4 +--- modules/wolframalpha/__init__.py | 6 ++---- 8 files changed, 14 insertions(+), 36 deletions(-) diff --git a/modules/bilibili/bili_api.py b/modules/bilibili/bili_api.py index 2c2f473f2d..5e5de63cfb 100644 --- a/modules/bilibili/bili_api.py +++ b/modules/bilibili/bili_api.py @@ -1,7 +1,4 @@ -import traceback - from core.builtins import Bot, Embed, EmbedField, ErrorMessage, Image, Plain, Url -from core.logger import Logger from core.utils.http import get_url from core.utils.web_render import webrender @@ -23,7 +20,7 @@ async def get_video_info(msg: Bot.MessageSession, query, get_detail=False, use_e if str(e).startswith('412'): await msg.finish(ErrorMessage('{bilibili.message.error.rejected}', locale=msg.locale.locale)) else: - Logger.error(traceback.format_exc()) + raise e view = res['data']['View'] stat = view['stat'] diff --git a/modules/bugtracker/bugtracker.py b/modules/bugtracker/bugtracker.py index f702fa55d5..c3158cd331 100644 --- a/modules/bugtracker/bugtracker.py +++ b/modules/bugtracker/bugtracker.py @@ -1,5 +1,4 @@ import os -import traceback import aiohttp import ujson as json @@ -59,7 +58,7 @@ async def bugtracker_get(msg, mojira_id: str): if str(e).startswith('401'): return msg.locale.t("bugtracker.message.get_failed"), None else: - Logger.error(traceback.format_exc()) + raise e if mojira_id not in spx_cache: get_spx = await get_url('https://spxx-db.teahouse.team/crowdin/zh-CN/zh_CN.json', 200) if get_spx: diff --git a/modules/cytoid/profile.py b/modules/cytoid/profile.py index f0b9a89ec1..b67cd86f25 100644 --- a/modules/cytoid/profile.py +++ b/modules/cytoid/profile.py @@ -1,9 +1,6 @@ -import traceback - import ujson as json from core.builtins import Bot, Image, Plain -from core.logger import Logger from core.utils.http import get_url from .dbutils import CytoidBindInfoManager @@ -23,7 +20,7 @@ async def cytoid_profile(msg: Bot.MessageSession): if str(e).startswith('404'): await msg.finish(msg.locale.t('cytoid.message.user_not_found')) else: - Logger.error(traceback.format_exc()) + raise e uid = profile['user']['uid'] nick = profile['user']['name'] avatar = profile['user']['avatar']['large'] diff --git a/modules/github/repo.py b/modules/github/repo.py index 3be0bcd0e7..0089f8c70c 100644 --- a/modules/github/repo.py +++ b/modules/github/repo.py @@ -1,10 +1,6 @@ -import asyncio -import traceback - from core.builtins import Bot, Image, Plain, Url from core.dirty_check import rickroll -from core.logger import Logger -from core.utils.http import get_url +from core.utils.http import download, get_url from modules.github.utils import time_diff, dirty_check, darkCheck @@ -59,16 +55,13 @@ async def repo(msg: Bot.MessageSession, name: str): else: await msg.send_message([Plain(message)]) - async def download(): - download_pic = await download( - f'https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/{result["full_name"]}') - if download_pic: - await msg.finish([Image(download_pic)], quote=False) - - asyncio.create_task(download()) + download_pic = await download( + f'https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/{result["full_name"]}') + if download_pic: + await msg.finish([Image(download_pic)], quote=False) except ValueError as e: if str(e).startswith('404'): await msg.finish(msg.locale.t("github.message.repo.not_found")) else: - Logger.error(traceback.format_exc()) + raise e \ No newline at end of file diff --git a/modules/github/user.py b/modules/github/user.py index ffe0ad9679..05ca134b11 100644 --- a/modules/github/user.py +++ b/modules/github/user.py @@ -1,8 +1,5 @@ -import traceback - from core.builtins import Url, Bot from core.dirty_check import rickroll -from core.logger import Logger from core.utils.http import get_url from modules.github.utils import time_diff, dirty_check, darkCheck @@ -48,4 +45,4 @@ async def user(msg: Bot.MessageSession, name: str): if str(e).startswith('404'): await msg.finish(msg.locale.t("github.message.repo.not_found")) else: - Logger.error(traceback.format_exc()) + raise e \ No newline at end of file diff --git a/modules/osu/profile.py b/modules/osu/profile.py index 9877f2f9c6..be024ddaa9 100644 --- a/modules/osu/profile.py +++ b/modules/osu/profile.py @@ -6,7 +6,6 @@ from config import Config from core.builtins import Bot from core.exceptions import ConfigValueError -from core.logger import Logger from core.utils.http import get_url @@ -65,7 +64,7 @@ async def osu_profile(msg: Bot.MessageSession, uid, mode): if str(e).startswith('401'): raise ConfigValueError(msg.locale.t("error.config.invalid")) else: - Logger.error(traceback.format_exc()) + raise e except Exception: Logger.error(traceback.format_exc()) await msg.finish(msg.locale.t('osu.message.not_found')) diff --git a/modules/tweet/__init__.py b/modules/tweet/__init__.py index 9df0d8f2be..63ec587dc5 100644 --- a/modules/tweet/__init__.py +++ b/modules/tweet/__init__.py @@ -1,5 +1,4 @@ import re -import traceback import ujson as json @@ -7,7 +6,6 @@ from core.builtins.message import Image, Url from core.component import module from core.dirty_check import check_bool, rickroll -from core.logger import Logger from core.utils.http import download, get_url from core.utils.text import isint from core.utils.web_render import webrender @@ -41,7 +39,7 @@ async def _(msg: Bot.MessageSession, tweet: str): if str(e).startswith('404'): await msg.finish(msg.locale.t('tweet.message.invalid')) else: - Logger.error(traceback.format_exc()) + raise e res_json = json.loads(res) if not res_json['data']: diff --git a/modules/wolframalpha/__init__.py b/modules/wolframalpha/__init__.py index 0737814942..28fa67dc5f 100644 --- a/modules/wolframalpha/__init__.py +++ b/modules/wolframalpha/__init__.py @@ -1,5 +1,4 @@ import os -import traceback import urllib.parse from PIL import Image @@ -8,7 +7,6 @@ from core.component import module from core.dirty_check import rickroll from core.exceptions import ConfigValueError -from core .logger import Logger from core.utils.http import download, get_url from .check import secret_check @@ -44,7 +42,7 @@ async def _(msg: Bot.MessageSession, query: str): if str(e).startswith('501'): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) else: - Logger.error(traceback.format_exc()) + raise e @w.handle('ask {{wolframalpha.help.ask}}') @@ -62,4 +60,4 @@ async def _(msg: Bot.MessageSession, question: str): if str(e).startswith('501'): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) else: - Logger.error(traceback.format_exc()) + raise e \ No newline at end of file