Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 在加载 drivers 引发 ImportError 时,使用 raise from e 而不是 raise from None #1688

Closed
shoucandanghehe opened this issue Feb 8, 2023 · 0 comments · Fixed by #1689
Labels
enhancement New feature or request

Comments

@shoucandanghehe
Copy link
Contributor

是否在使用中遇到某些问题而需要新的特性?请描述:

昨天在nb qq群里帮一个人 debug fastapi 加载失败,最后发现是系统 python 有问题,无法加载 _ssl 模块
JZZ0PN6UQ_5Y`XF )II}Z E

如果使用raise from e一开始就可以知道是无法加载 _ssl 模块

描述你所需要的特性:

在加载 drivers 引发 ImportError 时,使用 raise from e 而不是 raise from None

try:
import uvicorn
from fastapi.responses import Response
from fastapi import FastAPI, Request, UploadFile, status
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
except ImportError: # pragma: no cover
raise ImportError(
"Please install FastAPI by using `pip install nonebot2[fastapi]`"
) from None

try:
    import uvicorn
    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant