refactor!: remove unnecessary error enum and result type aliases (#7875)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir
2023-10-17 19:10:21 +03:00
committed by GitHub
parent ed32257d04
commit 12b8d18bf7
6 changed files with 35 additions and 53 deletions

View File

@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---
Removed `tauri::path::Error` and added its variants to `tauri::Error`.

View File

@@ -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<T, ::tauri::Error>`
pub type Result<T> = std::result::Result<T, Error>;

View File

@@ -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<T, ::tauri::Error>`
pub type Result<T> = std::result::Result<T, Error>;
/// A task to run on the main thread.
pub type SyncTask = Box<dyn FnOnce() + Send>;

View File

@@ -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<T> = std::result::Result<T, Error>;
/// 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<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}

View File

@@ -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;

View File

@@ -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<T> = StdResult<T, Box<dyn std::error::Error>>;
/// Mobile APIs.
#[cfg(mobile)]
pub mod mobile;
/// The result type of Tauri plugin module.
pub type Result<T> = StdResult<T, Box<dyn std::error::Error>>;
/// The plugin interface.
pub trait Plugin<R: Runtime>: Send {
/// The plugin name. Used as key on the plugin config object.
@@ -592,7 +593,7 @@ impl<R: Runtime> PluginStore<R> {
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()))
})
}