diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-12T13·48+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-12-12T18·06+0000 |
commit | 30d82efa774f72e6d33c2070b32d365121654c54 (patch) | |
tree | f0842e93b043c1dcad569127a9904f06c8112a4b /tvix/castore/src/blobservice/sled.rs | |
parent | 91456c3520a03e0f3b73224f1d80c56a5392fe32 (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/castore/src/blobservice/sled.rs')
-rw-r--r-- | tvix/castore/src/blobservice/sled.rs | 15 |
1 files changed, 8 insertions, 7 deletions
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<bool, Error> { + async fn has(&self, digest: &B3Digest) -> io::Result<bool> { 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<Option<Box<dyn BlobReader>>, Error> { + async fn open_read(&self, digest: &B3Digest) -> io::Result<Option<Box<dyn BlobReader>>> { 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<B3Digest, Error> { + async fn close(&mut self) -> io::Result<B3Digest> { 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 { |