diff --git a/.changes/tauri-extranous-result-types-removal.md b/.changes/tauri-extranous-result-types-removal.md new file mode 100644 index 00000000000..3b380a4139d --- /dev/null +++ b/.changes/tauri-extranous-result-types-removal.md @@ -0,0 +1,5 @@ +--- +'tauri': 'major:breaking' +--- + +Removed `tauri::path::Error` and added its variants to `tauri::Error`. diff --git a/core/tauri/src/error.rs b/core/tauri/src/error.rs index a1e1db01f6b..986714f8db7 100644 --- a/core/tauri/src/error.rs +++ b/core/tauri/src/error.rs @@ -107,7 +107,30 @@ 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), /// window not found. #[error("window not found")] WindowNotFound, } + +/// `Result` +pub type Result = std::result::Result; diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index e6304ef046d..17893559b1a 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; @@ -161,9 +160,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 d6a03646dfc..00000000000 --- 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 9c4b89ea336..795884738f5 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 048b1935478..e814110f0b2 100644 --- a/core/tauri/src/plugin.rs +++ b/core/tauri/src/plugin.rs @@ -6,6 +6,7 @@ use crate::{ app::PageLoadPayload, + error::Error, ipc::{Invoke, InvokeHandler}, utils::config::PluginConfig, AppHandle, RunEvent, Runtime, Window, @@ -17,13 +18,13 @@ use url::Url; use std::{fmt, result::Result as StdResult, sync::Arc}; +/// The result type of Tauri plugin module. +pub type Result = StdResult>; + /// 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. @@ -592,7 +593,7 @@ impl PluginStore { app, config.0.get(plugin.name()).cloned().unwrap_or_default(), ) - .map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string())) + .map_err(|e| Error::PluginInitialization(plugin.name().to_string(), e.to_string())) }) }