From 6a8a8a41ba7a5f0eab1cbba03faf5914f03c95f3 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Wed, 16 Aug 2023 13:20:36 -0400 Subject: [PATCH] fix(core): improve error handling for copy and remove (#18656) (cherry picked from commit 13925ba5764ab55d167cd5fa13bf43aad1961d6d) --- packages/nx/src/native/cache/file_ops.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/native/cache/file_ops.rs b/packages/nx/src/native/cache/file_ops.rs index cafdfbfd068cf..4fe9b31f4b303 100644 --- a/packages/nx/src/native/cache/file_ops.rs +++ b/packages/nx/src/native/cache/file_ops.rs @@ -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, ©_options)?; + fs_extra::copy_items(&[src], dest_parent, ©_options).map_err(|err| match err.kind { + ErrorKind::Io(err_kind) => anyhow::Error::new(err_kind), + _ => anyhow::Error::new(err), + })?; + Ok(()) }