From 30d82efa774f72e6d33c2070b32d365121654c54 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 12 Dec 2023 15:48:01 +0200 Subject: refactor(tvix/castore/blobservice): use io::Result in trait For all these calls, the caller has enough context about what it did, so it should be fine to use io::Result here. We pretty much only constructed crate::Error::StorageError before anyways, so this conveys *more* information. Change-Id: I5cabb3769c9c2314bab926d34dda748fda9d3ccc Reviewed-on: https://cl.tvl.fyi/c/depot/+/10328 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/store/src/nar/mod.rs | 4 ++-- tvix/store/src/nar/renderer.rs | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tvix/store') diff --git a/tvix/store/src/nar/mod.rs b/tvix/store/src/nar/mod.rs index 25a9e18826c8..c1a7fc2a933f 100644 --- a/tvix/store/src/nar/mod.rs +++ b/tvix/store/src/nar/mod.rs @@ -1,5 +1,5 @@ use data_encoding::BASE64; -use tvix_castore::{B3Digest, Error}; +use tvix_castore::B3Digest; mod import; mod renderer; @@ -11,7 +11,7 @@ pub use renderer::write_nar; #[derive(Debug, thiserror::Error)] pub enum RenderError { #[error("failure talking to a backing store client: {0}")] - StoreError(Error), + StoreError(#[source] std::io::Error), #[error("unable to find directory {}, referred from {:?}", .0, .1)] DirectoryNotFound(B3Digest, bytes::Bytes), diff --git a/tvix/store/src/nar/renderer.rs b/tvix/store/src/nar/renderer.rs index 2904f912fc14..f510a9c76e60 100644 --- a/tvix/store/src/nar/renderer.rs +++ b/tvix/store/src/nar/renderer.rs @@ -10,12 +10,10 @@ use std::{ }; use tokio::io::{self, AsyncWrite, BufReader}; use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; -use tracing::warn; use tvix_castore::{ blobservice::BlobService, directoryservice::DirectoryService, proto::{self as castorepb, NamedNode}, - Error, }; /// Invoke [write_nar], and return the size and sha256 digest of the produced @@ -110,14 +108,11 @@ async fn walk_node( .map_err(RenderError::NARWriterError)?; } castorepb::node::Node::File(proto_file_node) => { - let digest = proto_file_node.digest.clone().try_into().map_err(|_e| { - warn!( - file_node = ?proto_file_node, - "invalid digest length in file node", - ); - - RenderError::StoreError(Error::StorageError( - "invalid digest len in file node".to_string(), + let digest_len = proto_file_node.digest.len(); + let digest = proto_file_node.digest.clone().try_into().map_err(|_| { + RenderError::StoreError(io::Error::new( + io::ErrorKind::Other, + format!("invalid digest len {} in file node", digest_len), )) })?; @@ -143,13 +138,15 @@ async fn walk_node( .map_err(RenderError::NARWriterError)?; } castorepb::node::Node::Directory(proto_directory_node) => { + let digest_len = proto_directory_node.digest.len(); let digest = proto_directory_node .digest .clone() .try_into() - .map_err(|_e| { - RenderError::StoreError(Error::StorageError( - "invalid digest len in directory node".to_string(), + .map_err(|_| { + RenderError::StoreError(io::Error::new( + io::ErrorKind::InvalidData, + format!("invalid digest len {} in directory node", digest_len), )) })?; @@ -157,7 +154,7 @@ async fn walk_node( match directory_service .get(&digest) .await - .map_err(RenderError::StoreError)? + .map_err(|e| RenderError::StoreError(e.into()))? { // if it's None, that's an error! None => { -- cgit 1.4.1