From ab0533210f17109131071a2e7eedde33abfcbe94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Wed, 19 Feb 2025 16:53:26 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20error=20=E4=BC=9A=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E8=AF=A6=E7=BB=86=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3=E5=B8=B8=E8=A7=81=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=20(#270)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/error.rs | 17 +++++++++++------ crates/bili_sync/src/task/video_downloader.rs | 6 +++--- crates/bili_sync/src/workflow.rs | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/bili_sync/src/error.rs b/crates/bili_sync/src/error.rs index f16a098..9d1c7a0 100644 --- a/crates/bili_sync/src/error.rs +++ b/crates/bili_sync/src/error.rs @@ -24,15 +24,20 @@ impl From> for ExecutionStatus { match res { Ok(status) => status, Err(err) => { - // error decoding response body - if let Some(error) = err.downcast_ref::() { - if error.is_decode() { + if let Some(error) = err.downcast_ref::() { + let error_kind = error.kind(); + if error_kind == io::ErrorKind::PermissionDenied + || (error_kind == io::ErrorKind::Other + && error.get_ref().is_some_and(|e| { + e.downcast_ref::() + .is_some_and(|e| e.is_decode() || e.is_body() || e.is_timeout()) + })) + { return ExecutionStatus::Ignored(err); } } - // 文件系统的权限错误 - if let Some(error) = err.downcast_ref::() { - if error.kind() == io::ErrorKind::PermissionDenied { + if let Some(error) = err.downcast_ref::() { + if error.is_decode() || error.is_body() || error.is_timeout() { return ExecutionStatus::Ignored(err); } } diff --git a/crates/bili_sync/src/task/video_downloader.rs b/crates/bili_sync/src/task/video_downloader.rs index adb8bd3..513dc0b 100644 --- a/crates/bili_sync/src/task/video_downloader.rs +++ b/crates/bili_sync/src/task/video_downloader.rs @@ -23,20 +23,20 @@ pub async fn video_downloader(connection: Arc) { break 'inner; } Err(e) => { - error!("获取 mixin key 遇到错误:{e},等待下一轮执行"); + error!("获取 mixin key 遇到错误:{:#},等待下一轮执行", e); break 'inner; } }; if anchor != chrono::Local::now().date_naive() { if let Err(e) = bili_client.check_refresh().await { - error!("检查刷新 Credential 遇到错误:{e},等待下一轮执行"); + error!("检查刷新 Credential 遇到错误:{:#},等待下一轮执行", e); break 'inner; } anchor = chrono::Local::now().date_naive(); } for (args, path) in ¶ms { if let Err(e) = process_video_source(*args, &bili_client, path, &connection).await { - error!("处理过程遇到错误:{e}"); + error!("处理过程遇到错误:{:#}", e); } } info!("本轮任务执行完毕,等待下一轮执行"); diff --git a/crates/bili_sync/src/workflow.rs b/crates/bili_sync/src/workflow.rs index 4ced309..43fcf77 100644 --- a/crates/bili_sync/src/workflow.rs +++ b/crates/bili_sync/src/workflow.rs @@ -109,7 +109,7 @@ pub async fn fetch_video_details( match info { Err(e) => { error!( - "获取视频 {} - {} 的详细信息失败,错误为:{}", + "获取视频 {} - {} 的详细信息失败,错误为:{:#}", &video_model.bvid, &video_model.name, e ); if let Some(BiliError::RequestFailed(-404, _)) = e.downcast_ref::() { @@ -270,11 +270,11 @@ pub async fn download_video_pages( ExecutionStatus::Succeeded => info!("处理视频「{}」{}成功", &video_model.name, task_name), ExecutionStatus::Ignored(e) => { error!( - "处理视频「{}」{}出现常见错误,已忽略: {}", + "处理视频「{}」{}出现常见错误,已忽略: {:#}", &video_model.name, task_name, e ) } - ExecutionStatus::Failed(e) => error!("处理视频「{}」{}失败: {}", &video_model.name, task_name, e), + ExecutionStatus::Failed(e) => error!("处理视频「{}」{}失败: {:#}", &video_model.name, task_name, e), }); if let ExecutionStatus::Failed(e) = results.into_iter().nth(4).context("page download result not found")? { if e.downcast_ref::().is_some() { @@ -469,12 +469,12 @@ pub async fn download_page( ), ExecutionStatus::Ignored(e) => { error!( - "处理视频「{}」第 {} 页{}出现常见错误,已忽略: {}", + "处理视频「{}」第 {} 页{}出现常见错误,已忽略: {:#}", &video_model.name, page_model.pid, task_name, e ) } ExecutionStatus::Failed(e) => error!( - "处理视频「{}」第 {} 页{}失败: {}", + "处理视频「{}」第 {} 页{}失败: {:#}", &video_model.name, page_model.pid, task_name, e ), });