Skip to content

Commit da1e879

Browse files
authored
feat(core): improve and cleanup the Error enum (#3748)
1 parent 1099a96 commit da1e879

File tree

15 files changed

+63
-33
lines changed

15 files changed

+63
-33
lines changed

.changes/error-send-sync.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
The `Error` enum is now `Send + Sync`.

.changes/runtime-error-sync.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-runtime": patch
3+
---
4+
5+
Force `Error` boxed errors to be `Sync`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
The `App::setup` closure can now return a boxed error directly.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<T: UserEvent> ClipboardManager for ClipboardManagerWrapper<T> {
550550
/// Wrapper around a [`wry::application::window::Icon`] that can be created from an [`WindowIcon`].
551551
pub struct WryIcon(WryWindowIcon);
552552

553-
fn icon_err<E: std::error::Error + Send + 'static>(e: E) -> Error {
553+
fn icon_err<E: std::error::Error + Send + Sync + 'static>(e: E) -> Error {
554554
Error::InvalidIcon(Box::new(e))
555555
}
556556

core/tauri-runtime/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum UserAttentionType {
9898
pub enum Error {
9999
/// Failed to create webview.
100100
#[error("failed to create webview: {0}")]
101-
CreateWebview(Box<dyn std::error::Error + Send>),
101+
CreateWebview(Box<dyn std::error::Error + Send + Sync>),
102102
/// Failed to create window.
103103
#[error("failed to create window")]
104104
CreateWindow,
@@ -118,16 +118,16 @@ pub enum Error {
118118
#[cfg(feature = "system-tray")]
119119
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
120120
#[error("error encountered during tray setup: {0}")]
121-
SystemTray(Box<dyn std::error::Error + Send>),
121+
SystemTray(Box<dyn std::error::Error + Send + Sync>),
122122
/// Failed to load window icon.
123123
#[error("invalid icon: {0}")]
124-
InvalidIcon(Box<dyn std::error::Error + Send>),
124+
InvalidIcon(Box<dyn std::error::Error + Send + Sync>),
125125
/// Failed to get monitor on window operation.
126126
#[error("failed to get monitor")]
127127
FailedToGetMonitor,
128128
/// Global shortcut error.
129129
#[error(transparent)]
130-
GlobalShortcut(Box<dyn std::error::Error + Send>),
130+
GlobalShortcut(Box<dyn std::error::Error + Send + Sync>),
131131
#[error("Invalid header name: {0}")]
132132
InvalidHeaderName(#[from] InvalidHeaderName),
133133
#[error("Invalid header value: {0}")]

core/tauri/src/api/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Matches {
9090
/// use tauri::api::cli::get_matches;
9191
/// tauri::Builder::default()
9292
/// .setup(|app| {
93-
/// let matches = get_matches(app.config().tauri.cli.as_ref().unwrap(), app.package_info()).unwrap();
93+
/// let matches = get_matches(app.config().tauri.cli.as_ref().unwrap(), app.package_info())?;
9494
/// Ok(())
9595
/// });
9696
/// ```

core/tauri/src/api/ipc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn serialize_js_with<T: Serialize, F: FnOnce(&str) -> String>(
125125
/// "console.log({}, {})",
126126
/// serialize_js(&Foo { bar: "bar".to_string() }).unwrap(),
127127
/// serialize_js(&Bar { baz: 0 }).unwrap()),
128-
/// ).unwrap();
128+
/// )?;
129129
/// Ok(())
130130
/// });
131131
/// ```

core/tauri/src/api/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl BaseDirectory {
125125
/// use tauri::Manager;
126126
/// tauri::Builder::default()
127127
/// .setup(|app| {
128-
/// let path = tauri::api::path::parse(&app.config(), app.package_info(), &app.env(), "$HOME/.bashrc").unwrap();
128+
/// let path = tauri::api::path::parse(&app.config(), app.package_info(), &app.env(), "$HOME/.bashrc")?;
129129
/// assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.bashrc");
130130
/// Ok(())
131131
/// });
@@ -202,7 +202,7 @@ pub fn parse<P: AsRef<Path>>(
202202
/// &app.env(),
203203
/// "path/to/something",
204204
/// Some(BaseDirectory::Config)
205-
/// ).expect("failed to resolve path");
205+
/// )?;
206206
/// assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/path/to/something");
207207
/// Ok(())
208208
/// });

core/tauri/src/api/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use command::*;
4646
///
4747
/// tauri::Builder::default()
4848
/// .setup(|app| {
49-
/// let current_binary_path = current_binary(&app.env()).unwrap();
49+
/// let current_binary_path = current_binary(&app.env())?;
5050
/// Ok(())
5151
/// });
5252
/// ```

core/tauri/src/api/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Program {
101101
/// tauri::Builder::default()
102102
/// .setup(|app| {
103103
/// // open the given URL on the system default browser
104-
/// open(&app.shell_scope(), "https://github.com/tauri-apps/tauri", None).unwrap();
104+
/// open(&app.shell_scope(), "https://github.com/tauri-apps/tauri", None)?;
105105
/// Ok(())
106106
/// });
107107
/// ```

0 commit comments

Comments
 (0)