Skip to content

Commit

Permalink
fix(opener): return error if path not exists (#2253)
Browse files Browse the repository at this point in the history
  • Loading branch information
betamos authored Jan 3, 2025
1 parent 3461a7a commit a9ac1e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-opener-open-path-error.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions plugins/opener/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ pub fn open_url<P: AsRef<str>, S: AsRef<str>>(url: P, with: Option<S>) -> crate:
/// ```
pub fn open_path<P: AsRef<Path>, S: AsRef<str>>(path: P, with: Option<S>) -> 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)
}

0 comments on commit a9ac1e3

Please # to comment.