about summary refs log tree commit diff
path: root/tvix/store/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-12T13·48+0200
committerclbot <clbot@tvl.fyi>2023-12-12T18·06+0000
commit30d82efa774f72e6d33c2070b32d365121654c54 (patch)
treef0842e93b043c1dcad569127a9904f06c8112a4b /tvix/store/src
parent91456c3520a03e0f3b73224f1d80c56a5392fe32 (diff)
refactor(tvix/castore/blobservice): use io::Result in trait r/7207
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 <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src')
-rw-r--r--tvix/store/src/nar/mod.rs4
-rw-r--r--tvix/store/src/nar/renderer.rs25
2 files changed, 13 insertions, 16 deletions
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 => {