diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs index b1f6bbb974..f2a879e709 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -31,6 +31,15 @@ pub enum CacheError { #[class(type)] #[error("Cache name cannot be empty")] EmptyName, + #[class(type)] + #[error("Cache is not available")] + NotAvailable, + #[class(type)] + #[error("Cache not found")] + NotFound, + #[class(type)] + #[error("Cache deletion is not supported")] + DeletionNotSupported, #[class(generic)] #[error(transparent)] Sqlite(#[from] rusqlite::Error), @@ -46,6 +55,12 @@ pub enum CacheError { #[class(inherit)] #[error("{0}")] Io(#[from] std::io::Error), + #[class(type)] + #[error(transparent)] + InvalidHeaderName(#[from] hyper::header::InvalidHeaderName), + #[class(type)] + #[error(transparent)] + InvalidHeaderValue(#[from] hyper::header::InvalidHeaderValue), #[class(generic)] #[error("Failed to create cache storage directory {}", .dir.display())] CacheStorageDirectory { diff --git a/ext/cache/lscache.rs b/ext/cache/lscache.rs index 1a421a14da..d27ddcf16e 100644 --- a/ext/cache/lscache.rs +++ b/ext/cache/lscache.rs @@ -82,7 +82,7 @@ impl Cache for LscBackend { &self, _cache_name: String, ) -> Result { - Err(type_error("Cache deletion is not supported")) + Err(CacheError::DeletionNotSupported) } /// Writes an entry to the cache. @@ -92,7 +92,7 @@ impl Cache for LscBackend { resource: Option>, ) -> Result<(), CacheError> { let Some(shard) = self.shard.borrow().as_ref().cloned() else { - return Err(type_error("Cache is not available")); + return Err(CacheError::NotAvailable); }; let Some(cache_name) = self @@ -101,7 +101,7 @@ impl Cache for LscBackend { .get(request_response.cache_id as usize) .cloned() else { - return Err(type_error("Cache not found")); + return Err(CacheError::NotFound); }; let object_key = build_cache_object_key( cache_name.as_bytes(), @@ -143,7 +143,7 @@ impl Cache for LscBackend { let body = try_stream! { if let Some(resource) = resource { loop { - let (size, buf) = resource.clone().read_byob(BufMutView::new(64 * 1024)).await?; + let (size, buf) = resource.clone().read_byob(BufMutView::new(64 * 1024)).await.map_err(CacheError::Other)?; if size == 0 { break; } @@ -167,7 +167,7 @@ impl Cache for LscBackend { CacheError, > { let Some(shard) = self.shard.borrow().as_ref().cloned() else { - return Err(type_error("Cache is not available")); + return Err(CacheError::NotAvailable); }; let Some(cache_name) = self .id2name @@ -175,7 +175,7 @@ impl Cache for LscBackend { .get(request.cache_id as usize) .cloned() else { - return Err(type_error("Cache not found")); + return Err(CacheError::NotFound); }; let object_key = build_cache_object_key( cache_name.as_bytes(), @@ -269,7 +269,7 @@ impl Cache for LscBackend { request: CacheDeleteRequest, ) -> Result { let Some(shard) = self.shard.borrow().as_ref().cloned() else { - return Err(type_error("Cache is not available")); + return Err(CacheError::NotAvailable); }; let Some(cache_name) = self @@ -278,7 +278,7 @@ impl Cache for LscBackend { .get(request.cache_id as usize) .cloned() else { - return Err(type_error("Cache not found")); + return Err(CacheError::NotFound); }; let object_key = build_cache_object_key( cache_name.as_bytes(),