From a9ac1e3c939cec4338a9422ef02323c1d4dde6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Didrik=20Nordstr=C3=B6m?= Date: Sat, 4 Jan 2025 00:27:01 +0100 Subject: [PATCH] fix(opener): return error if path not exists (#2253) --- .changes/fix-opener-open-path-error.md | 6 ++++++ plugins/opener/src/open.rs | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 .changes/fix-opener-open-path-error.md diff --git a/.changes/fix-opener-open-path-error.md b/.changes/fix-opener-open-path-error.md new file mode 100644 index 00000000..b752a586 --- /dev/null +++ b/.changes/fix-opener-open-path-error.md @@ -0,0 +1,6 @@ +--- +"opener": patch +"opener-js": patch +--- + +Return an error in `open_path` if the file does not exist when opening with default application. \ No newline at end of file diff --git a/plugins/opener/src/open.rs b/plugins/opener/src/open.rs index da531472..a3d46c50 100644 --- a/plugins/opener/src/open.rs +++ b/plugins/opener/src/open.rs @@ -53,5 +53,9 @@ pub fn open_url, S: AsRef>(url: P, with: Option) -> crate: /// ``` pub fn open_path, S: AsRef>(path: P, with: Option) -> crate::Result<()> { let path = path.as_ref(); + if with.is_none() { + // Returns an IO error if not exists, and besides `exists()` is a shorthand for `metadata()` + _ = path.metadata()?; + } open(path, with) }