about summary refs log tree commit diff
path: root/tvix/store/src/errors.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-02-12T11·34+0100
committerflokli <flokli@flokli.de>2023-03-10T10·58+0000
commit69516f1f6877a4de7dd92a758c83dd7ffc3254e3 (patch)
tree918faea8d3f5142579c0533fc94d48c5945d1210 /tvix/store/src/errors.rs
parentbdf0725def6c72946c2fa86eefbba15c8b680b5f (diff)
feat(tvix/store/blobservice): add GRPCBlobServiceWrapper r/5910
This takes a BlobService and ChunkService in the constructor, and
provides a [proto::blob_service_server::BlobService] trait for it.

Implementing proto::blob_service_server::BlobService is a lot of surface
to cover, and providing this wrapper will make individual
implementations taking care of how to store chunks or chunking
information much simpler.

Change-Id: Ia7b46484fb3ac9104354d496ff2922dca96ff7b9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8092
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/errors.rs')
-rw-r--r--tvix/store/src/errors.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/tvix/store/src/errors.rs b/tvix/store/src/errors.rs
index 7f74744284..25e87c8aa2 100644
--- a/tvix/store/src/errors.rs
+++ b/tvix/store/src/errors.rs
@@ -1,5 +1,6 @@
 use std::sync::PoisonError;
 use thiserror::Error;
+use tonic::Status;
 
 /// Errors related to communication with the store.
 #[derive(Debug, Error)]
@@ -16,3 +17,12 @@ impl<T> From<PoisonError<T>> for Error {
         Error::StorageError(value.to_string())
     }
 }
+
+impl From<Error> for Status {
+    fn from(value: Error) -> Self {
+        match value {
+            Error::InvalidRequest(msg) => Status::invalid_argument(msg),
+            Error::StorageError(msg) => Status::data_loss(format!("storage error: {}", msg)),
+        }
+    }
+}