Skip to content

Commit

Permalink
fix(object_storage): not having access to original boto3 ClientError
Browse files Browse the repository at this point in the history
All the exceptions wrapping boto3 ClientError with set the ClientError
as their root cause
  • Loading branch information
kkiani committed Aug 2, 2024
1 parent 17c918d commit fdf5b23
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/damavand/cloud/aws/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ def write(self, object: bytes, path: str):
except ClientError as e:
match utils.error_code_from_boto3(e):
case "AccessDenied" | "403":
raise ResourceAccessDenied(name=self.name)
raise ResourceAccessDenied(name=self.name) from e
case _:
logger.exception("Failed to write the object to AWS.")
raise RuntimeException()
raise RuntimeException() from e

@runtime
def read(self, path: str) -> bytes:
Expand All @@ -75,12 +74,11 @@ def read(self, path: str) -> bytes:
except ClientError as e:
match utils.error_code_from_boto3(e):
case "AccessDenied" | "403":
raise ResourceAccessDenied(name=self.name)
raise ResourceAccessDenied(name=self.name) from e
case "NoSuchKey" | "404":
raise ObjectNotFound(name=path)
raise ObjectNotFound(name=path) from e
case _:
logger.exception("Failed to read the object from AWS")
raise RuntimeException()
raise RuntimeException() from e

@runtime
def delete(self, path: str):
Expand All @@ -89,10 +87,9 @@ def delete(self, path: str):
except ClientError as e:
match utils.error_code_from_boto3(e):
case "AccessDenied" | "403":
raise ResourceAccessDenied(name=self.name)
raise ResourceAccessDenied(name=self.name) from e
case _:
logger.exception("Failed to delete the object from AWS.")
raise RuntimeException()
raise RuntimeException() from e

@runtime
def list(self) -> Iterable[str]:
Expand All @@ -109,10 +106,9 @@ def list(self) -> Iterable[str]:
except ClientError as e:
match utils.error_code_from_boto3(e):
case "AccessDenied" | "403":
raise ResourceAccessDenied(name=self.name)
raise ResourceAccessDenied(name=self.name) from e
case _:
logger.exception("Failed to list objects from AWS.")
raise RuntimeException()
raise RuntimeException() from e

@runtime
def exist(self, path: str) -> bool:
Expand All @@ -125,10 +121,9 @@ def exist(self, path: str) -> bool:
case "NoSuchKey" | "404":
return False
case "AccessDenied" | "403":
raise ResourceAccessDenied(name=self.name)
raise ResourceAccessDenied(name=self.name) from e
case _:
logger.exception("Failed to check the object existence in AWS.")
raise RuntimeException()
raise RuntimeException() from e

@buildtime
def to_pulumi(self) -> PulumiResource:
Expand Down

0 comments on commit fdf5b23

Please sign in to comment.