Skip to content

Commit

Permalink
refactor!: remove unnecessary error enum and result type aliases
Browse files Browse the repository at this point in the history
ref: #7756
  • Loading branch information
amrbashir committed Sep 21, 2023
1 parent a2021c3 commit 729338c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 53 deletions.
6 changes: 6 additions & 0 deletions .changes/tauri-extranous-result-types-removal.md
Original file line number Diff line number Diff line change
@@ -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`
23 changes: 23 additions & 0 deletions core/tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, ::tauri::Error>`
pub type Result<T> = std::result::Result<T, Error>;
6 changes: 1 addition & 5 deletions core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,9 +161,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>;

Expand Down
42 changes: 0 additions & 42 deletions core/tauri/src/path/error.rs

This file was deleted.

3 changes: 1 addition & 2 deletions core/tauri/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions core/tauri/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use crate::{
app::PageLoadPayload,
error::*,
ipc::{Invoke, InvokeHandler},
utils::config::PluginConfig,
AppHandle, RunEvent, Runtime, Window,
Expand All @@ -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<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.
Expand Down

0 comments on commit 729338c

Please sign in to comment.