From 729338c553e02b238a675bd26839be57ad3dd709 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Thu, 21 Sep 2023 07:38:11 +0300 Subject: [PATCH] refactor!: remove unnecessary error enum and result type aliases ref: https://github.com/tauri-apps/tauri/issues/7756 --- .../tauri-extranous-result-types-removal.md | 6 +++ core/tauri/src/error.rs | 23 ++++++++++ core/tauri/src/lib.rs | 6 +-- core/tauri/src/path/error.rs | 42 ------------------- core/tauri/src/path/mod.rs | 3 +- core/tauri/src/plugin.rs | 6 +-- 6 files changed, 33 insertions(+), 53 deletions(-) create mode 100644 .changes/tauri-extranous-result-types-removal.md delete mode 100644 core/tauri/src/path/error.rs diff --git a/.changes/tauri-extranous-result-types-removal.md b/.changes/tauri-extranous-result-types-removal.md new file mode 100644 index 000000000000..cd2941627a89 --- /dev/null +++ b/.changes/tauri-extranous-result-types-removal.md @@ -0,0 +1,6 @@ +--- +'tauri': 'major:breaking' +--- + +- Removed `tauri::path::Error` and added its variants to `tauri::Error` +- Removed `tauri::plath::Result` and `tauri::plugin::Result` aliases, you should use `tauri::Result` diff --git a/core/tauri/src/error.rs b/core/tauri/src/error.rs index 8de7cec0d01b..eb48a04c9daa 100644 --- a/core/tauri/src/error.rs +++ b/core/tauri/src/error.rs @@ -110,4 +110,27 @@ pub enum Error { #[cfg(all(desktop, feature = "tray-icon"))] #[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))] BadTrayIcon(#[from] tray_icon::BadIcon), + /// Path does not have a parent. + #[error("path does not have a parent")] + NoParent, + /// Path does not have an extension. + #[error("path does not have an extension")] + NoExtension, + /// Path does not have a basename. + #[error("path does not have a basename")] + NoBasename, + /// Cannot resolve current directory. + #[error("failed to read current dir: {0}")] + CurrentDir(std::io::Error), + /// Unknown path. + #[cfg(not(target_os = "android"))] + #[error("unknown path")] + UnknownPath, + /// Failed to invoke mobile plugin. + #[cfg(target_os = "android")] + #[error(transparent)] + PluginInvoke(#[from] crate::plugin::mobile::PluginInvokeError), } + +/// `Result` +pub type Result = std::result::Result; diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index eabcd02d1e22..4f3765768c55 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -65,8 +65,7 @@ pub use cocoa; #[cfg(target_os = "macos")] #[doc(hidden)] pub use embed_plist; -/// The Tauri error enum. -pub use error::Error; +pub use error::{Error, Result}; #[cfg(target_os = "ios")] #[doc(hidden)] pub use swift_rs; @@ -162,9 +161,6 @@ pub use plugin::mobile::{handle_android_plugin_response, send_channel_data}; #[doc(hidden)] pub use tauri_runtime_wry::wry; -/// `Result` -pub type Result = std::result::Result; - /// A task to run on the main thread. pub type SyncTask = Box; diff --git a/core/tauri/src/path/error.rs b/core/tauri/src/path/error.rs deleted file mode 100644 index d6a03646dfc6..000000000000 --- a/core/tauri/src/path/error.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019-2023 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -use serde::{ser::Serializer, Serialize}; - -/// Path result. -pub type Result = std::result::Result; - -/// Path error. -#[derive(Debug, thiserror::Error)] -pub enum Error { - /// Path does not have a parent. - #[error("path does not have a parent")] - NoParent, - /// Path does not have an extension. - #[error("path does not have an extension")] - NoExtension, - /// Path does not have a basename. - #[error("path does not have a basename")] - NoBasename, - /// Cannot resolve current directory. - #[error("failed to read current dir: {0}")] - CurrentDir(std::io::Error), - /// Unknown path. - #[cfg(not(target_os = "android"))] - #[error("unknown path")] - UnknownPath, - /// Failed to invoke mobile plugin. - #[cfg(target_os = "android")] - #[error(transparent)] - PluginInvoke(#[from] crate::plugin::mobile::PluginInvokeError), -} - -impl Serialize for Error { - fn serialize(&self, serializer: S) -> std::result::Result - where - S: Serializer, - { - serializer.serialize_str(self.to_string().as_ref()) - } -} diff --git a/core/tauri/src/path/mod.rs b/core/tauri/src/path/mod.rs index 9c4b89ea336d..795884738f53 100644 --- a/core/tauri/src/path/mod.rs +++ b/core/tauri/src/path/mod.rs @@ -14,8 +14,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr}; use serialize_to_javascript::{default_template, DefaultTemplate, Template}; mod commands; -mod error; -pub use error::*; +pub use crate::error::*; #[cfg(target_os = "android")] mod android; diff --git a/core/tauri/src/plugin.rs b/core/tauri/src/plugin.rs index 048b1935478e..9c783c8d2966 100644 --- a/core/tauri/src/plugin.rs +++ b/core/tauri/src/plugin.rs @@ -6,6 +6,7 @@ use crate::{ app::PageLoadPayload, + error::*, ipc::{Invoke, InvokeHandler}, utils::config::PluginConfig, AppHandle, RunEvent, Runtime, Window, @@ -15,15 +16,12 @@ use serde_json::Value as JsonValue; use tauri_macros::default_runtime; use url::Url; -use std::{fmt, result::Result as StdResult, sync::Arc}; +use std::{fmt, sync::Arc}; /// Mobile APIs. #[cfg(mobile)] pub mod mobile; -/// The result type of Tauri plugin module. -pub type Result = StdResult>; - /// The plugin interface. pub trait Plugin: Send { /// The plugin name. Used as key on the plugin config object.