🐛 fix aiohttp config trierule bugs

This commit is contained in:
yanyongyu
2021-12-27 02:26:02 +08:00
parent fd9ec5e6fa
commit c1e06c2ec0
3 changed files with 23 additions and 13 deletions

View File

@ -29,6 +29,9 @@ from pydantic.env_settings import (
env_file_sentinel, env_file_sentinel,
) )
from nonebot.log import logger
from nonebot.utils import escape_tag
class CustomEnvSettings(EnvSettingsSource): class CustomEnvSettings(EnvSettingsSource):
def __call__(self, settings: BaseSettings) -> Dict[str, Any]: def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
@ -90,9 +93,11 @@ class CustomEnvSettings(EnvSettingsSource):
env_val = env_vars[env_name] env_val = env_vars[env_name]
try: try:
if env_val: if env_val:
env_val = settings.__config__.json_loads(env_val) env_val = settings.__config__.json_loads(env_val.strip())
except ValueError as e: except ValueError as e:
pass logger.opt(colors=True, exception=e).trace(
f"Error while parsing JSON for {escape_tag(env_name)}. Assumed as string."
)
d[env_name] = env_val d[env_name] = env_val

View File

@ -72,7 +72,7 @@ class Mixin(ForwardMixin):
else: else:
raise RuntimeError(f"Unsupported HTTP version: {setup.version}") raise RuntimeError(f"Unsupported HTTP version: {setup.version}")
session = aiohttp.ClientSession(version=version, trust_env=True) async with aiohttp.ClientSession(version=version, trust_env=True) as session:
async with session.ws_connect( async with session.ws_connect(
setup.url, setup.url,
method=setup.method, method=setup.method,

View File

@ -303,7 +303,12 @@ async def handle_event(bot: "Bot", event: "Event") -> None:
return return
# Trie Match # Trie Match
try:
TrieRule.get_value(bot, event, state) TrieRule.get_value(bot, event, state)
except Exception as e:
logger.opt(colors=True, exception=e).warning(
"Error while parsing command for event"
)
break_flag = False break_flag = False
for priority in sorted(matchers.keys()): for priority in sorted(matchers.keys()):