Skip to content

Commit

Permalink
fix(core): improve error handling for copy and remove (#18656)
Browse files Browse the repository at this point in the history
(cherry picked from commit 13925ba)
  • Loading branch information
Cammisuli authored and FrozenPandaz committed Aug 16, 2023
1 parent 0e6a353 commit 6a8a8a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/nx/src/native/cache/file_ops.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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(())
}

Expand Down

0 comments on commit 6a8a8a4

Please sign in to comment.