From 08dfc956e84f60d955a10674e7582e5e69c14d5b Mon Sep 17 00:00:00 2001 From: gurjotkaur20 Date: Wed, 10 Jan 2024 11:49:01 +0530 Subject: [PATCH 1/2] fix: error handling on server start when s3 bucket is not found --- server/src/storage.rs | 4 ++++ server/src/storage/s3.rs | 8 ++++++++ server/src/storage/store_metadata.rs | 8 ++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/src/storage.rs b/server/src/storage.rs index c966b0026..ec03b1d04 100644 --- a/server/src/storage.rs +++ b/server/src/storage.rs @@ -140,6 +140,10 @@ pub enum ObjectStorageError { #[error("{0} not found")] NoSuchKey(String), + // custom + #[error("{0}")] + Custom(String), + // Could not connect to object storage #[error("Connection Error: {0}")] ConnectionError(Box), diff --git a/server/src/storage/s3.rs b/server/src/storage/s3.rs index 79b38426d..d2fa8ad30 100644 --- a/server/src/storage/s3.rs +++ b/server/src/storage/s3.rs @@ -256,6 +256,14 @@ impl S3 { .with_label_values(&["PUT", status]) .observe(time); + + if let Err(object_store::Error::NotFound { source, .. }) = &resp { + let source_str = source.to_string(); + if source_str.contains("NoSuchBucket") { + return Err(ObjectStorageError::Custom(format!("Bucket '{}' does not exist in S3.", self.bucket).to_string())); + } + } + resp.map(|_| ()).map_err(|err| err.into()) } diff --git a/server/src/storage/store_metadata.rs b/server/src/storage/store_metadata.rs index b47aa3d95..2c80ba835 100644 --- a/server/src/storage/store_metadata.rs +++ b/server/src/storage/store_metadata.rs @@ -156,14 +156,14 @@ pub async fn resolve_parseable_metadata() -> Result Date: Wed, 10 Jan 2024 12:15:22 +0530 Subject: [PATCH 2/2] fix: cargo fmt --- server/src/storage.rs | 2 +- server/src/storage/s3.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/storage.rs b/server/src/storage.rs index ec03b1d04..306c95e33 100644 --- a/server/src/storage.rs +++ b/server/src/storage.rs @@ -140,7 +140,7 @@ pub enum ObjectStorageError { #[error("{0} not found")] NoSuchKey(String), - // custom + // custom #[error("{0}")] Custom(String), diff --git a/server/src/storage/s3.rs b/server/src/storage/s3.rs index d2fa8ad30..55a9efb8d 100644 --- a/server/src/storage/s3.rs +++ b/server/src/storage/s3.rs @@ -256,12 +256,13 @@ impl S3 { .with_label_values(&["PUT", status]) .observe(time); - if let Err(object_store::Error::NotFound { source, .. }) = &resp { - let source_str = source.to_string(); - if source_str.contains("NoSuchBucket") { - return Err(ObjectStorageError::Custom(format!("Bucket '{}' does not exist in S3.", self.bucket).to_string())); - } + let source_str = source.to_string(); + if source_str.contains("NoSuchBucket") { + return Err(ObjectStorageError::Custom( + format!("Bucket '{}' does not exist in S3.", self.bucket).to_string(), + )); + } } resp.map(|_| ()).map_err(|err| err.into())