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/castore/src/blobservice/sled.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'tvix/castore/src/blobservice/sled.rs') diff --git a/tvix/castore/src/blobservice/sled.rs b/tvix/castore/src/blobservice/sled.rs index f7bf33e8c50f..3dd4bff7bc8e 100644 --- a/tvix/castore/src/blobservice/sled.rs +++ b/tvix/castore/src/blobservice/sled.rs @@ -34,19 +34,19 @@ impl SledBlobService { #[async_trait] impl BlobService for SledBlobService { #[instrument(skip(self), fields(blob.digest=%digest))] - async fn has(&self, digest: &B3Digest) -> Result { + async fn has(&self, digest: &B3Digest) -> io::Result { match self.db.contains_key(digest.as_slice()) { Ok(has) => Ok(has), - Err(e) => Err(Error::StorageError(e.to_string())), + Err(e) => Err(io::Error::new(io::ErrorKind::Other, e.to_string())), } } #[instrument(skip(self), fields(blob.digest=%digest))] - async fn open_read(&self, digest: &B3Digest) -> Result>, Error> { + async fn open_read(&self, digest: &B3Digest) -> io::Result>> { match self.db.get(digest.as_slice()) { Ok(None) => Ok(None), Ok(Some(data)) => Ok(Some(Box::new(Cursor::new(data[..].to_vec())))), - Err(e) => Err(Error::StorageError(e.to_string())), + Err(e) => Err(io::Error::new(io::ErrorKind::Other, e.to_string())), } } @@ -118,12 +118,13 @@ impl tokio::io::AsyncWrite for SledBlobWriter { #[async_trait] impl BlobWriter for SledBlobWriter { - async fn close(&mut self) -> Result { + async fn close(&mut self) -> io::Result { if self.writers.is_none() { match &self.digest { Some(digest) => Ok(digest.clone()), - None => Err(crate::Error::StorageError( - "previously closed with error".to_string(), + None => Err(io::Error::new( + io::ErrorKind::NotConnected, + "already closed", )), } } else { -- cgit 1.4.1