diff --git a/services/blob/src/http/errors.rs b/services/blob/src/http/errors.rs --- a/services/blob/src/http/errors.rs +++ b/services/blob/src/http/errors.rs @@ -48,22 +48,21 @@ } }, BlobServiceError::S3(s3_err) => match s3_err { - S3Error::AwsSdk(aws_err) => match aws_err.as_ref() { - aws_sdk_s3::Error::NotFound(_) | aws_sdk_s3::Error::NoSuchKey(_) => { - error!( + s3_error if s3_error.is_s3_object_not_found() => { + error!( errorType = error_types::S3_ERROR, "Data inconsistency! Blob is present in database but not present in S3!" ); - ErrorInternalServerError("server error") - } - err => { - error!( - errorType = error_types::S3_ERROR, - "Received an unexpected AWS S3 error: {0:?} - {0}", err - ); - ErrorInternalServerError("server error") - } - }, + ErrorInternalServerError("server error") + } + S3Error::AwsSdk(aws_err) => { + error!( + errorType = error_types::S3_ERROR, + "Received an unexpected AWS S3 error: {0:?} - {0}", + aws_err.as_ref() + ); + ErrorInternalServerError("server error") + } S3Error::EmptyUpload => ErrorBadRequest("empty upload"), unexpected => { error!( diff --git a/services/blob/src/s3.rs b/services/blob/src/s3.rs --- a/services/blob/src/s3.rs +++ b/services/blob/src/s3.rs @@ -28,6 +28,19 @@ InvalidAttribute(&'static str), } +impl Error { + pub fn is_s3_object_not_found(&self) -> bool { + let Self::AwsSdk(aws_error) = self else { + return false; + }; + + matches!( + aws_error.as_ref(), + S3Error::NotFound(_) | S3Error::NoSuchKey(_) + ) + } +} + #[derive(Debug, derive_more::Error)] pub enum S3PathError { MissingSeparator(#[error(ignore)] String), diff --git a/services/blob/src/service.rs b/services/blob/src/service.rs --- a/services/blob/src/service.rs +++ b/services/blob/src/service.rs @@ -277,9 +277,14 @@ Some(ddb_size) => *ddb_size, None => { let s3_path = BlobItemInput::new(&blob_hash).s3_path; - let s3_size = self.s3.get_object_size(&s3_path).await?; - updated_values.push((blob_hash.clone(), s3_size)); - s3_size + match self.s3.get_object_size(&s3_path).await { + Ok(s3_size) => { + updated_values.push((blob_hash.clone(), s3_size)); + s3_size + } + Err(s3_err) if s3_err.is_s3_object_not_found() => 0, + Err(s3_err) => return Err(s3_err.into()), + } } }; results.insert(blob_hash, blob_size); diff --git a/shared/comm-lib/src/blob/client.rs b/shared/comm-lib/src/blob/client.rs --- a/shared/comm-lib/src/blob/client.rs +++ b/shared/comm-lib/src/blob/client.rs @@ -282,7 +282,8 @@ Ok(result) } - /// Fetches blob sizes for requested blob hashes. + /// Fetches blob sizes for requested blob hashes. If blob with given hash + /// doesn't exist, it's returned size will be 0. /// This endpoint is callable only by other services. /// /// # Example