Skip to content

Commit 0a64f85

Browse files
authored
perf:optimize error message for S3BucketNotFoundError (#407)
1 parent 5e85f33 commit 0a64f85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

megfile/errors.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,16 @@ def translate_s3_error(s3_error: Exception, s3_url: PathLike) -> Exception:
342342
elif isinstance(s3_error, ClientError):
343343
code = client_error_code(s3_error)
344344
if code in ("NoSuchBucket"):
345-
return S3BucketNotFoundError(
346-
"No such bucket: %r"
347-
% s3_error.response.get( # pytype: disable=attribute-error
345+
bucket_or_url = (
346+
s3_error.response.get( # pytype: disable=attribute-error
348347
"Error", {}
349348
).get("BucketName")
350349
or s3_url
351350
)
351+
return S3BucketNotFoundError(
352+
"No such bucket: %r, endpoint: %r"
353+
% (bucket_or_url, s3_endpoint_url(s3_url))
354+
)
352355
if code in ("404", "NoSuchKey"):
353356
return S3FileNotFoundError("No such file: %r" % s3_url)
354357
if code in ("401", "403", "AccessDenied"):

0 commit comments

Comments
 (0)