-
Notifications
You must be signed in to change notification settings - Fork 701
[BUG]下载失败引发程序崩溃:网络异常处理逻辑存在严重缺陷 (ConnectionReset & HTTP 412) #289
Description
Describe the bug (问题描述)
在使用 BiliNote (v1.1.1) 下载 Bilibili 视频生成笔记时,当遇到网络连接中断 (ConnectionResetError) 或 Bilibili 服务器返回 HTTP 412 错误时,程序不仅下载失败,还会在异常处理阶段发生二次崩溃 (TypeError),导致任务状态无法正确保存,用户界面卡死或报错信息不明确。
主要存在两个层面的问题:
网络层:yt-dlp 在下载过程中遭遇连接重置或 412 预条件失败(通常因缺少 Cookie 或反爬拦截)。
代码层:app/services/note.py 和 app/routers/note.py 中的异常捕获逻辑存在语法错误和类型错误,导致程序无法优雅地处理下载失败的情况。
To Reproduce (复现步骤)
运行 BiliNote v1.1.1。
输入一个 Bilibili 视频链接 (例如: BV1owrpYKEtP)。
场景 A:在网络不稳定或防火墙拦截时,触发 ConnectionResetError (10054)。
场景 B:在未配置 Cookie 或被 Bilibili 风控时,触发 HTTP Error 412: Precondition Failed。
观察控制台日志,程序抛出 TypeError 并终止任务,而非显示友好的错误提示。前端看不出来是什么错误。
日志:
[download] Got error: ('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))
...
File "app\services\note.py", line 316, in generate
raise f'❌ 笔记生成流程异常终止,task_id={task_id},错误信息:{e}'
TypeError: exceptions must derive from BaseException
During handling of the above exception, another exception occurred:
...
File "app\routers\note.py", line 61, in save_note_to_file
json.dump(asdict(note), f, ensure_ascii=False, indent=2)
TypeError: asdict() should be called on dataclass instances
ERROR: [BiliBili] 1owrpYKEtP: Unable to download webpage: HTTP Error 412: Precondition Failed
...
yt_dlp.utils.DownloadError: ERROR: [BiliBili] 1owrpYKEtP: Unable to download webpage: HTTP Error 412: Precondition Failed
...
File "app\services\note.py", line 316, in generate
raise f'❌ 笔记生成流程异常终止,task_id={task_id},错误信息:{e}'
TypeError: exceptions must derive from BaseException
During handling of the above exception, another exception occurred:
...
File "app\routers\note.py", line 61, in save_note_to_file
json.dump(asdict(note), f, ensure_ascii=False, indent=2)
TypeError: asdict() should be called on dataclass instances