Skip to content

Commit 28e7136

Browse files
authored
Merge pull request #1178 from tonymushah/1045-use-errorwrapper-instead-of-error-on-graphql-queries
1045 use errorwrapper instead of error on graphql queries
2 parents 3cf5bc4 + 8ee3c0e commit 28e7136

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+508
-333
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "special-eureka"
3-
version = "0.2.2-2"
3+
version = "0.2.2-3"
44
description = "a manga reader desktop app build with tauri"
55
authors = ["tonymushah"]
66
license = ""

src-tauri/mangadex/src/error.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{backtrace::Backtrace, ops::Deref};
1+
use std::backtrace::Backtrace;
22

33
use async_graphql::ErrorExtensions;
44
use uuid::Uuid;
@@ -146,6 +146,16 @@ pub enum Error {
146146
ChapterPageNotLoaded { page: u32, chapter: Uuid },
147147
#[error("the {} chapter pages data can't be read", .0)]
148148
CannotReadChapterPagesData(Uuid),
149+
#[error("Object creator not found")]
150+
ObjectCreatorNotFound,
151+
#[error("Related manga not found")]
152+
RelatedMangaNotFound,
153+
#[error("Related user not found")]
154+
RelatedUserNotFound,
155+
#[error("Related cover_art not found")]
156+
RelatedCoverArtNotFound,
157+
#[error(transparent)]
158+
RelationshipConversion(mangadex_api_types_rust::error::RelationshipConversionError),
149159
}
150160

151161
impl Error {
@@ -216,28 +226,28 @@ impl ErrorExtensions for Error {
216226
}
217227
}
218228

219-
#[derive(Debug, Clone)]
220-
pub struct ErrorWrapper(std::sync::Arc<Error>);
229+
#[derive(Debug)]
230+
pub struct ErrorWrapper(Error);
221231

222232
impl<E> From<E> for ErrorWrapper
223233
where
224234
E: Into<Error>,
225235
{
226236
fn from(value: E) -> Self {
227-
Self(std::sync::Arc::new(value.into()))
237+
Self(value.into())
228238
}
229239
}
230240

231241
impl AsRef<Error> for ErrorWrapper {
232242
fn as_ref(&self) -> &Error {
233-
self.0.deref()
243+
&self.0
234244
}
235245
}
236246

237247
impl ErrorWrapper {
238248
#[cfg_attr(feature = "hotpath", hotpath::measure)]
239-
pub fn into_inner(self) -> Option<Error> {
240-
std::sync::Arc::into_inner(self.0)
249+
pub fn into_inner(self) -> Error {
250+
self.0
241251
}
242252
}
243253

@@ -246,3 +256,7 @@ impl From<ErrorWrapper> for async_graphql::Error {
246256
value.0.extend()
247257
}
248258
}
259+
260+
pub(crate) mod wrapped {
261+
pub type Result<T, E = super::ErrorWrapper> = std::result::Result<T, E>;
262+
}

src-tauri/mangadex/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(crate) type Result<T, E = error::Error> = std::result::Result<T, E>;
3333
pub(crate) use plugin_setup::PluginSetupResult;
3434

3535
pub use error::Error;
36+
pub(crate) use error::ErrorWrapper;
3637

3738
pub fn init<R: Runtime>() -> MizukiPlugin<R, Q, M, S> {
3839
mizuki::Builder::new(

src-tauri/mangadex/src/mutation/api_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use mangadex_api_input_types::api_client::{
55
use mangadex_api_schema_rust::{ApiObjectNoRelationships, v5::ApiClientAttributes};
66
use uuid::Uuid;
77

8-
use crate::Result;
8+
use crate::error::wrapped::Result;
99
use crate::{
1010
objects::api_client::ApiClient,
1111
utils::{

src-tauri/mangadex/src/mutation/author.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use mangadex_api_input_types::author::{create::AuthorCreateParams, edit::AuthorE
33
use mangadex_api_schema_rust::{ApiObjectNoRelationships, v5::AuthorAttributes};
44
use uuid::Uuid;
55

6-
use crate::Result;
6+
use crate::error::wrapped::Result;
77
use crate::utils::traits_utils::{MangadexAsyncGraphQLContextExt, MangadexTauriManagerExt};
88
use crate::{
99
objects::author::Author,

src-tauri/mangadex/src/mutation/captcha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::Result;
1+
use crate::error::wrapped::Result;
22
use async_graphql::{Context, Object};
33
use mangadex_api_input_types::captcha::solve::CaptchaSolveParams;
44

src-tauri/mangadex/src/mutation/chapter.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub mod pages;
22

33
use crate::{
4-
Result,
54
error::Error,
5+
error::wrapped::Result,
66
query::download_state::DownloadStateQueries,
77
store::{
88
TauriManagerMangadexStoreExtractor, types::enums::chapter_quality::ChapterQualityStore,
@@ -85,7 +85,10 @@ impl ChapterMutations {
8585
ins_handle::add_in_queue(&tauri_handle, id)?;
8686

8787
let res = download_chapter(&tauri_handle, id, quality.into()).await;
88-
let state = DownloadStateQueries.chapter(ctx, id).await?;
88+
let state = DownloadStateQueries
89+
.chapter(ctx, id)
90+
.await
91+
.map_err(|e| e.into_inner())?;
8992
if let Err(_err) = res {
9093
ins_handle::add_in_failed(&tauri_handle, id)?;
9194
Ok(state)

src-tauri/mangadex/src/mutation/chapter/pages.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_graphql::{Context, Object};
22
use uuid::Uuid;
33

4+
use crate::error::wrapped::Result;
45
use crate::{
56
store::types::enums::chapter_quality::DownloadMode,
67
utils::traits_utils::{MangadexAsyncGraphQLContextExt, MangadexTauriManagerExt},
@@ -14,7 +15,7 @@ pub struct ChapterPagesStoreMutation {
1415
#[Object]
1516
#[cfg_attr(feature = "hotpath", hotpath::measure_all)]
1617
impl ChapterPagesStoreMutation {
17-
pub async fn fetch_metadata(&self, ctx: &Context<'_>) -> crate::Result<bool> {
18+
pub async fn fetch_metadata(&self, ctx: &Context<'_>) -> Result<bool> {
1819
let app = ctx.get_app_handle::<tauri::Wry>()?;
1920
let store = app.get_chapter_pages_store();
2021
if let Ok(store_read) = store.read() {
@@ -27,7 +28,7 @@ impl ChapterPagesStoreMutation {
2728
Ok(false)
2829
}
2930
}
30-
pub async fn start_caching(&self, ctx: &Context<'_>) -> crate::Result<bool> {
31+
pub async fn start_caching(&self, ctx: &Context<'_>) -> Result<bool> {
3132
let app = ctx.get_app_handle::<tauri::Wry>()?;
3233
let store = app.get_chapter_pages_store();
3334
if let Ok(store_read) = store.read() {
@@ -40,7 +41,7 @@ impl ChapterPagesStoreMutation {
4041
Ok(false)
4142
}
4243
}
43-
pub async fn refetch_page(&self, ctx: &Context<'_>, page: u32) -> crate::Result<bool> {
44+
pub async fn refetch_page(&self, ctx: &Context<'_>, page: u32) -> Result<bool> {
4445
let app = ctx.get_app_handle::<tauri::Wry>()?;
4546
let store = app.get_chapter_pages_store();
4647
if let Ok(store_read) = store.read() {
@@ -53,7 +54,7 @@ impl ChapterPagesStoreMutation {
5354
Ok(false)
5455
}
5556
}
56-
pub async fn resend_page(&self, ctx: &Context<'_>, page: u32) -> crate::Result<bool> {
57+
pub async fn resend_page(&self, ctx: &Context<'_>, page: u32) -> Result<bool> {
5758
let app = ctx.get_app_handle::<tauri::Wry>()?;
5859
let store = app.get_chapter_pages_store();
5960
if let Ok(store_read) = store.read() {
@@ -66,7 +67,7 @@ impl ChapterPagesStoreMutation {
6667
Ok(false)
6768
}
6869
}
69-
pub async fn resend_all(&self, ctx: &Context<'_>) -> crate::Result<bool> {
70+
pub async fn resend_all(&self, ctx: &Context<'_>) -> Result<bool> {
7071
let app = ctx.get_app_handle::<tauri::Wry>()?;
7172
let store = app.get_chapter_pages_store();
7273
if let Ok(store_read) = store.read() {
@@ -79,7 +80,7 @@ impl ChapterPagesStoreMutation {
7980
Ok(false)
8081
}
8182
}
82-
pub async fn refetch_incompletes(&self, ctx: &Context<'_>) -> crate::Result<bool> {
83+
pub async fn refetch_incompletes(&self, ctx: &Context<'_>) -> Result<bool> {
8384
let app = ctx.get_app_handle::<tauri::Wry>()?;
8485
let store = app.get_chapter_pages_store();
8586
if let Ok(store_read) = store.read() {
@@ -98,7 +99,7 @@ impl ChapterPagesStoreMutation {
9899
export_path: String,
99100
page: u32,
100101
defer: Option<bool>,
101-
) -> crate::Result<Option<String>> {
102+
) -> Result<Option<String>> {
102103
let app = ctx.get_app_handle::<tauri::Wry>()?;
103104
let store = app.get_chapter_pages_store();
104105
let handle = {

src-tauri/mangadex/src/mutation/cover.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use mangadex_api_schema_rust::{ApiObjectNoRelationships, v5::CoverAttributes};
1515
use uuid::Uuid;
1616

1717
use crate::{
18-
Result,
1918
error::Error,
19+
error::wrapped::Result,
2020
query::download_state::DownloadStateQueries,
2121
utils::{download::cover::cover_download, traits_utils::MangadexAsyncGraphQLContextExt},
2222
};
@@ -77,7 +77,10 @@ impl CoverMutations {
7777
pub async fn download(&self, ctx: &Context<'_>, id: Uuid) -> Result<DownloadState> {
7878
let app = ctx.get_app_handle::<tauri::Wry>()?;
7979
let res = cover_download(app, id).await;
80-
let state = DownloadStateQueries.cover(ctx, id).await?;
80+
let state = DownloadStateQueries
81+
.cover(ctx, id)
82+
.await
83+
.map_err(|e| e.into_inner())?;
8184
res?;
8285
Ok(state)
8386
}

0 commit comments

Comments
 (0)