Open jcbhmr opened 1 year ago
Here's where this came up and my temp solution for it:
#[napi]
pub async unsafe fn read(&self) -> Result<Buffer> {
// TODO: https://stackoverflow.com/a/54432441
// https://stackoverflow.com/a/35559417
let hook = panic::take_hook();
panic::set_hook(Box::new(|_| {}));
// https://stackoverflow.com/a/63159560/19522682
let vec = self.0.read().catch_unwind().await;
panic::set_hook(hook);
if vec.is_err() {
return Err(Error::from_reason("Panic"));
}
let vec = vec.unwrap();
let buffer = vec.into();
return Ok(buffer);
}
Oh, yeah that's bad, will take a look at that, in the meantime assuming that you are not building for web browsers you could just call .path() instead of .read(), and read the file yourself
I think it's this
.unwrap()
that's unwrapping the return value ofstd::fs::read()
that was stashed in the shared value...https://github.com/PolyMeilex/rfd/blob/25d879a854b606c2236b72c7c085ae776d413837/src/file_handle/native.rs#L52
...but since https://doc.rust-lang.org/stable/std/fs/fn.read.html returns a
Result<>
, theunwrap()
panics.