From c9d3946cb583631bc2ca4a1343f054f7ee64a626 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 30 Apr 2024 18:48:12 +0300 Subject: refactor(tvix/castore/import): restructure error types Have ingest_entries return an Error type with only three kinds: - Error while uploading a specific Directory - Error while finalizing the directory upload - Error from the producer Move all ingestion method-specific errors to the individual implementations. Change-Id: I2a015cb7ebc96d084cbe2b809f40d1b53a15daf3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11557 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: Connor Brewster --- tvix/castore/src/import/mod.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tvix/castore/src/import/mod.rs') diff --git a/tvix/castore/src/import/mod.rs b/tvix/castore/src/import/mod.rs index d2234846dcbc..bf21001822e0 100644 --- a/tvix/castore/src/import/mod.rs +++ b/tvix/castore/src/import/mod.rs @@ -26,7 +26,7 @@ use std::{ use tracing::instrument; mod error; -pub use error::Error; +pub use error::IngestionError; pub mod archive; pub mod fs; @@ -49,10 +49,14 @@ pub mod fs; /// /// On success, returns the root node. #[instrument(skip_all, ret(level = Level::TRACE), err)] -pub async fn ingest_entries(directory_service: DS, mut entries: S) -> Result +pub async fn ingest_entries( + directory_service: DS, + mut entries: S, +) -> Result> where DS: AsRef, - S: Stream> + Send + std::marker::Unpin, + S: Stream> + Send + std::marker::Unpin, + E: std::error::Error, { // For a given path, this holds the [Directory] structs as they are populated. let mut directories: HashMap = HashMap::default(); @@ -102,7 +106,10 @@ where maybe_directory_putter .get_or_insert_with(|| directory_service.as_ref().put_multiple_start()) .put(directory) - .await?; + .await + .map_err(|e| { + IngestionError::UploadDirectoryError(entry.path().to_path_buf(), e) + })?; Node::Directory(DirectoryNode { name, @@ -147,7 +154,10 @@ where // they're all persisted to the backend. if let Some(mut directory_putter) = maybe_directory_putter { #[cfg_attr(not(debug_assertions), allow(unused))] - let root_directory_digest = directory_putter.close().await?; + let root_directory_digest = directory_putter + .close() + .await + .map_err(|e| IngestionError::FinalizeDirectoryUpload(e))?; #[cfg(debug_assertions)] { -- cgit 1.4.1