Skip to content

Commit 590d43f

Browse files
authored
GH-47349: [C++] Include request ID in AWS S3 Error (#47351)
### Rationale for this change It is a uuid useful for debugging with AWS support team. Indeed, `minio` errors will print out a request ID by default. ### What changes are included in this PR? The request ID is appended to the end of the error message. ### Are these changes tested? New Python tests added where Request ID is expected. ### Are there any user-facing changes? No * GitHub Issue: #47349 Authored-by: Kit Lee <7000003+wingkitlee0@users.noreply.github.com> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent 886ca6f commit 590d43f

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

cpp/src/arrow/filesystem/s3_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ Status ErrorToStatus(const std::string& prefix, const std::string& operation,
189189
"'.";
190190
}
191191
}
192+
193+
auto request_id = error.GetRequestId();
194+
auto request_str = request_id.empty() ? "" : (" (Request ID: " + request_id + ")");
195+
192196
return Status::IOError(prefix, "AWS Error ", ss.str(), " during ", operation,
193-
" operation: ", error.GetMessage(),
197+
" operation: ", error.GetMessage(), request_str,
194198
wrong_region_msg.value_or(""));
195199
}
196200

python/pyarrow/tests/test_fs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ def subtree_s3fs(request, s3fs):
293293
"Resource": [
294294
"arn:aws:s3:::*"
295295
]
296+
297+
},
298+
{
299+
"Effect": "Deny",
300+
"Action": [
301+
"s3:DeleteObject"
302+
],
303+
"Resource": [
304+
"arn:aws:s3:::no-delete-bucket*"
305+
]
296306
}
297307
]
298308
}"""
@@ -534,6 +544,20 @@ def test_s3fs_limited_permissions_create_bucket(s3_server):
534544
with pytest.raises(pa.ArrowIOError, match="Would delete bucket"):
535545
fs.delete_dir('existing-bucket')
536546

547+
with pytest.raises(OSError, match="Request ID:"):
548+
fs.copy_file("existing-bucket/test-file", "existing-bucket/test-file-copy")
549+
550+
with pytest.raises(pa.ArrowIOError, match="Request ID:"):
551+
with fs.open_output_stream("non-existing-bucket/test-file") as f:
552+
f.write(b"test")
553+
554+
# Create a file in the protected bucket then try to delete it
555+
with fs.open_output_stream("no-delete-bucket/test-file") as f:
556+
f.write(b"test")
557+
558+
with pytest.raises(OSError, match="Request ID:"):
559+
fs.delete_file("no-delete-bucket/test-file")
560+
537561

538562
def test_file_info_constructor():
539563
dt = datetime.fromtimestamp(1568799826, timezone.utc)

python/pyarrow/tests/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ def _configure_s3_limited_user(s3_server, policy, username, password):
419419
# ... and a sample bucket for that user to write to
420420
_run_mc_command(mcdir, 'mb', 'myminio/existing-bucket',
421421
'--ignore-existing')
422+
# Create a protected bucket for testing no-delete-bucket policy
423+
_run_mc_command(mcdir, 'mb', 'myminio/no-delete-bucket',
424+
'--ignore-existing')
422425

423426
except FileNotFoundError:
424427
pytest.skip("Configuring limited s3 user failed")

0 commit comments

Comments
 (0)