fix(core): improve error handling for copy and remove (#18656)

This commit is contained in:
Jonathan Cammisuli 2023-08-16 13:20:36 -04:00 committed by GitHub
parent f670e7469f
commit 13925ba576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,14 @@
use std::fs;
use std::path::PathBuf;
use fs_extra::error::ErrorKind;
#[napi]
pub fn remove(src: String) -> anyhow::Result<()> {
fs_extra::remove_items(&[src]).map_err(anyhow::Error::from)
fs_extra::remove_items(&[src]).map_err(|err| match err.kind {
ErrorKind::Io(err_kind) => anyhow::Error::new(err_kind),
_ => anyhow::Error::new(err),
})
}
#[napi]
@ -19,7 +24,11 @@ pub fn copy(src: String, dest: String) -> anyhow::Result<()> {
fs::create_dir_all(dest_parent)?;
}
fs_extra::copy_items(&[src], dest_parent, &copy_options)?;
fs_extra::copy_items(&[src], dest_parent, &copy_options).map_err(|err| match err.kind {
ErrorKind::Io(err_kind) => anyhow::Error::new(err_kind),
_ => anyhow::Error::new(err),
})?;
Ok(())
}