Skip to content

Commit 21d721a

Browse files
authored
fix(deep-link): Add command name to linux errors (#2928)
1 parent 8abb31e commit 21d721a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.changes/deep-link-linux-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
deep-link: patch
3+
deep-link-js: patch
4+
---
5+
6+
On Linux, improved error messages when OS commands fail.

plugins/deep-link/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub enum Error {
2323
#[cfg(target_os = "linux")]
2424
#[error(transparent)]
2525
ParseIni(#[from] ini::ParseError),
26+
#[cfg(target_os = "linux")]
27+
#[error("Failed to run OS command `{0}`: {1}")]
28+
Execute(&'static str, #[source] std::io::Error),
2629
#[cfg(mobile)]
2730
#[error(transparent)]
2831
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),

plugins/deep-link/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ mod imp {
254254
///
255255
/// ## Platform-specific:
256256
///
257+
/// - **Linux**: Needs the `xdg-mime` and `update-desktop-database` commands available on the system.
257258
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
258259
pub fn register<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<()> {
259260
#[cfg(windows)]
@@ -332,11 +333,13 @@ mod imp {
332333

333334
Command::new("update-desktop-database")
334335
.arg(target)
335-
.status()?;
336+
.status()
337+
.map_err(|error| crate::Error::Execute("update-desktop-database", error))?;
336338

337339
Command::new("xdg-mime")
338340
.args(["default", &file_name, mime_type.as_str()])
339-
.status()?;
341+
.status()
342+
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;
340343

341344
Ok(())
342345
}
@@ -405,6 +408,7 @@ mod imp {
405408
///
406409
/// ## Platform-specific:
407410
///
411+
/// - **Linux**: Needs the `xdg-mime` command available on the system.
408412
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
409413
pub fn is_registered<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<bool> {
410414
#[cfg(windows)]
@@ -439,7 +443,8 @@ mod imp {
439443
"default",
440444
&format!("x-scheme-handler/{}", _protocol.as_ref()),
441445
])
442-
.output()?;
446+
.output()
447+
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;
443448

444449
Ok(String::from_utf8_lossy(&output.stdout).contains(&file_name))
445450
}

0 commit comments

Comments
 (0)