From 69c5852d6a4b60df814082aad796496a73884cf3 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 30 Apr 2025 19:04:46 -0400 Subject: [PATCH] fix(core): error when restoring http cache with no outputs --- packages/nx/src/native/cache/cache.rs | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/native/cache/cache.rs b/packages/nx/src/native/cache/cache.rs index 18e53cf9deb3d..e995ab154095d 100644 --- a/packages/nx/src/native/cache/cache.rs +++ b/packages/nx/src/native/cache/cache.rs @@ -301,9 +301,26 @@ impl NxCache { &outputs_path, &self.workspace_root ); - let sz = _copy(outputs_path, &self.workspace_root)?; + let sz = _copy(outputs_path, &self.workspace_root); - Ok(sz) + match sz { + Err(e) => { + let kind = underlying_io_error_kind(&e); + match kind { + Some(std::io::ErrorKind::NotFound) => { + trace!("No artifacts to copy: {:?}", e); + Ok(0) + } + _ => { + return Err(anyhow::anyhow!("Error copying files from cache: {:?}", e)); + } + } + } + Ok(sz) => { + trace!("Copied {} bytes from cache", sz); + Ok(sz) + } + } } #[napi] @@ -407,3 +424,13 @@ where } } } + +// From: https://docs.rs/anyhow/latest/anyhow/struct.Error.html#example-1 +fn underlying_io_error_kind(error: &anyhow::Error) -> Option { + for cause in error.chain() { + if let Some(io_error) = cause.downcast_ref::() { + return Some(io_error.kind()); + } + } + None +}