fix(opener): return error if path not exists (#2253)

This commit is contained in:
Didrik Nordström
2025-01-04 00:27:01 +01:00
committed by GitHub
parent 3461a7ae2c
commit a9ac1e3c93
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -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
View File
@@ -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)
}