Skip to content

Commit

Permalink
Remove traceback, raise instead
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf authored Jul 31, 2024
1 parent 69b01bb commit a12cefb
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 36 deletions.
5 changes: 1 addition & 4 deletions modules/bilibili/bili_api.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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']
Expand Down
3 changes: 1 addition & 2 deletions modules/bugtracker/bugtracker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import traceback

import aiohttp
import ujson as json
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions modules/cytoid/profile.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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']
Expand Down
19 changes: 6 additions & 13 deletions modules/github/repo.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions modules/github/user.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions modules/osu/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'))
Expand Down
4 changes: 1 addition & 3 deletions modules/tweet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import re
import traceback

import ujson as json

from core.builtins import Bot
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
Expand Down Expand Up @@ -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']:
Expand Down
6 changes: 2 additions & 4 deletions modules/wolframalpha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import traceback
import urllib.parse
from PIL import Image

Expand All @@ -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

Expand Down Expand Up @@ -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 <question> {{wolframalpha.help.ask}}')
Expand All @@ -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

0 comments on commit a12cefb

Please sign in to comment.