Skip to content

Commit a9ac1e3

Browse files
authored
fix(opener): return error if path not exists (#2253)
1 parent 3461a7a commit a9ac1e3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"opener": patch
3+
"opener-js": patch
4+
---
5+
6+
Return an error in `open_path` if the file does not exist when opening with default application.

plugins/opener/src/open.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ pub fn open_url<P: AsRef<str>, S: AsRef<str>>(url: P, with: Option<S>) -> crate:
5353
/// ```
5454
pub fn open_path<P: AsRef<Path>, S: AsRef<str>>(path: P, with: Option<S>) -> crate::Result<()> {
5555
let path = path.as_ref();
56+
if with.is_none() {
57+
// Returns an IO error if not exists, and besides `exists()` is a shorthand for `metadata()`
58+
_ = path.metadata()?;
59+
}
5660
open(path, with)
5761
}

0 commit comments

Comments
 (0)