0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-09 21:57:40 -04:00

map more errors

This commit is contained in:
Bartek Iwańczuk 2025-01-11 00:44:26 +01:00
parent 88903e14af
commit c144f7bf40
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 23 additions and 8 deletions

15
ext/cache/lib.rs vendored
View file

@ -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 {

16
ext/cache/lscache.rs vendored
View file

@ -82,7 +82,7 @@ impl Cache for LscBackend {
&self,
_cache_name: String,
) -> Result<bool, CacheError> {
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<Rc<dyn Resource>>,
) -> 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<bool, 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
@ -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(),