refactor: 使用 context 代替 ok_or 和 ok_or_else

This commit is contained in:
amtoaer
2025-01-21 18:06:54 +08:00
parent 0f25923c52
commit 1a32e38dc3
10 changed files with 44 additions and 53 deletions

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::path::Path;
use std::pin::Pin;
use anyhow::{anyhow, Result};
use anyhow::{Context, Result};
use async_trait::async_trait;
use bili_sync_entity::*;
use futures::Stream;
@@ -196,7 +196,7 @@ pub(super) async fn collection_from<'a>(
)
.one(connection)
.await?
.ok_or(anyhow!("collection not found"))?,
.context("collection not found")?,
),
Box::pin(collection.into_simple_video_stream()),
))

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::path::Path;
use std::pin::Pin;
use anyhow::{anyhow, Result};
use anyhow::{Context, Result};
use async_trait::async_trait;
use bili_sync_entity::*;
use futures::Stream;
@@ -153,7 +153,7 @@ pub(super) async fn favorite_from<'a>(
.filter(favorite::Column::FId.eq(favorite_info.id))
.one(connection)
.await?
.ok_or(anyhow!("favorite not found"))?,
.context("favorite not found")?,
),
Box::pin(favorite.into_video_stream()),
))

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::path::Path;
use std::pin::Pin;
use anyhow::{anyhow, Result};
use anyhow::{Context, Result};
use async_trait::async_trait;
use bili_sync_entity::*;
use futures::Stream;
@@ -169,7 +169,7 @@ pub(super) async fn submission_from<'a>(
.filter(submission::Column::UpperId.eq(upper.mid))
.one(connection)
.await?
.ok_or(anyhow!("submission not found"))?,
.context("submission not found")?,
),
Box::pin(submission.into_video_stream()),
))

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::path::Path;
use std::pin::Pin;
use anyhow::{anyhow, Result};
use anyhow::{Context, Result};
use async_trait::async_trait;
use bili_sync_entity::*;
use futures::Stream;
@@ -151,7 +151,7 @@ pub(super) async fn watch_later_from<'a>(
.filter(watch_later::Column::Id.eq(1))
.one(connection)
.await?
.ok_or(anyhow!("watch_later not found"))?,
.context("watch_later not found")?,
),
Box::pin(watch_later.into_video_stream()),
))