Skip to content

Commit

Permalink
refactor!: remove unnecessary error enum and result type aliases (#7875)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
amrbashir and lucasfernog committed Oct 17, 2023
1 parent ed32257 commit 12b8d18
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changes/tauri-extranous-result-types-removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---

Removed `tauri::path::Error` and added its variants to `tauri::Error`.
23 changes: 23 additions & 0 deletions core/tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
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 @@ -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>;

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
9 changes: 5 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::Error,
ipc::{Invoke, InvokeHandler},
utils::config::PluginConfig,
AppHandle, RunEvent, Runtime, Window,
Expand All @@ -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.
Expand Down Expand Up @@ -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()))
})
}

Expand Down

0 comments on commit 12b8d18

Please sign in to comment.