about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs35
1 files changed, 20 insertions, 15 deletions
diff --git a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
index a5c5776cd4ef..9f458182274d 100644
--- a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
+++ b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs
@@ -27,7 +27,7 @@ where
 {
     type ListStream = BoxStream<'static, tonic::Result<proto::PathInfo, Status>>;
 
-    #[instrument(skip(self))]
+    #[instrument(skip_all)]
     async fn get(
         &self,
         request: Request<proto::GetPathInfoRequest>,
@@ -43,7 +43,7 @@ where
                     Ok(None) => Err(Status::not_found("PathInfo not found")),
                     Ok(Some(path_info)) => Ok(Response::new(path_info)),
                     Err(e) => {
-                        warn!("failed to retrieve PathInfo: {}", e);
+                        warn!(err = %e, "failed to get PathInfo");
                         Err(e.into())
                     }
                 }
@@ -51,7 +51,7 @@ where
         }
     }
 
-    #[instrument(skip(self))]
+    #[instrument(skip_all)]
     async fn put(&self, request: Request<proto::PathInfo>) -> Result<Response<proto::PathInfo>> {
         let path_info = request.into_inner();
 
@@ -60,13 +60,13 @@ where
         match self.inner.put(path_info).await {
             Ok(path_info_new) => Ok(Response::new(path_info_new)),
             Err(e) => {
-                warn!("failed to insert PathInfo: {}", e);
+                warn!(err = %e, "failed to put PathInfo");
                 Err(e.into())
             }
         }
     }
 
-    #[instrument(skip(self))]
+    #[instrument(skip_all)]
     async fn calculate_nar(
         &self,
         request: Request<castorepb::Node>,
@@ -74,21 +74,26 @@ where
         match request.into_inner().node {
             None => Err(Status::invalid_argument("no root node sent")),
             Some(root_node) => {
-                let (nar_size, nar_sha256) = self
-                    .inner
-                    .calculate_nar(&root_node)
-                    .await
-                    .expect("error during nar calculation"); // TODO: handle error
+                if let Err(e) = root_node.validate() {
+                    warn!(err = %e, "invalid root node");
+                    Err(Status::invalid_argument("invalid root node"))?
+                }
 
-                Ok(Response::new(proto::CalculateNarResponse {
-                    nar_size,
-                    nar_sha256: nar_sha256.to_vec().into(),
-                }))
+                match self.inner.calculate_nar(&root_node).await {
+                    Ok((nar_size, nar_sha256)) => Ok(Response::new(proto::CalculateNarResponse {
+                        nar_size,
+                        nar_sha256: nar_sha256.to_vec().into(),
+                    })),
+                    Err(e) => {
+                        warn!(err = %e, "error during NAR calculation");
+                        Err(e.into())
+                    }
+                }
             }
         }
     }
 
-    #[instrument(skip(self))]
+    #[instrument(skip_all, err)]
     async fn list(
         &self,
         _request: Request<proto::ListPathInfoRequest>,