From 4c0d4065c5b1419519d5161e30bc183658448a88 Mon Sep 17 00:00:00 2001 From: scdhh <51957264+shoucandanghehe@users.noreply.github.com> Date: Thu, 9 Feb 2023 10:24:27 +0800 Subject: [PATCH] :sparkles: Use `raise from e` when load driver error (#1689) --- nonebot/drivers/aiohttp.py | 4 ++-- nonebot/drivers/fastapi.py | 4 ++-- nonebot/drivers/httpx.py | 4 ++-- nonebot/drivers/quart.py | 4 ++-- nonebot/drivers/websockets.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nonebot/drivers/aiohttp.py b/nonebot/drivers/aiohttp.py index 32814279..e4b6267d 100644 --- a/nonebot/drivers/aiohttp.py +++ b/nonebot/drivers/aiohttp.py @@ -27,10 +27,10 @@ from nonebot.drivers import HTTPVersion, ForwardMixin, ForwardDriver, combine_dr try: import aiohttp -except ImportError: # pragma: no cover +except ImportError as e: # pragma: no cover raise ImportError( "Please install aiohttp first to use this driver. `pip install nonebot2[aiohttp]`" - ) from None + ) from e class Mixin(ForwardMixin): diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index 7ac9cc45..aa76ff78 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -37,10 +37,10 @@ try: from fastapi.responses import Response from fastapi import FastAPI, Request, UploadFile, status from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect -except ImportError: # pragma: no cover +except ImportError as e: # pragma: no cover raise ImportError( "Please install FastAPI by using `pip install nonebot2[fastapi]`" - ) from None + ) from e def catch_closed(func): diff --git a/nonebot/drivers/httpx.py b/nonebot/drivers/httpx.py index c3c1165b..eb55c2be 100644 --- a/nonebot/drivers/httpx.py +++ b/nonebot/drivers/httpx.py @@ -31,10 +31,10 @@ from nonebot.drivers import ( try: import httpx -except ImportError: # pragma: no cover +except ImportError as e: # pragma: no cover raise ImportError( "Please install httpx by using `pip install nonebot2[httpx]`" - ) from None + ) from e class Mixin(ForwardMixin): diff --git a/nonebot/drivers/quart.py b/nonebot/drivers/quart.py index 9169d81a..f16134e3 100644 --- a/nonebot/drivers/quart.py +++ b/nonebot/drivers/quart.py @@ -37,10 +37,10 @@ try: from quart import Quart, Request, Response from quart.datastructures import FileStorage from quart import Websocket as QuartWebSocket -except ImportError: # pragma: no cover +except ImportError as e: # pragma: no cover raise ImportError( "Please install Quart by using `pip install nonebot2[quart]`" - ) from None + ) from e _AsyncCallable = TypeVar("_AsyncCallable", bound=Callable[..., Coroutine]) diff --git a/nonebot/drivers/websockets.py b/nonebot/drivers/websockets.py index 3dc166a1..808ff791 100644 --- a/nonebot/drivers/websockets.py +++ b/nonebot/drivers/websockets.py @@ -30,10 +30,10 @@ from nonebot.drivers import ForwardMixin, ForwardDriver, combine_driver try: from websockets.exceptions import ConnectionClosed from websockets.legacy.client import Connect, WebSocketClientProtocol -except ImportError: # pragma: no cover +except ImportError as e: # pragma: no cover raise ImportError( "Please install websockets by using `pip install nonebot2[websockets]`" - ) from None + ) from e logger = logging.Logger("websockets.client", "INFO") logger.addHandler(LoguruHandler())