Skip to content

Commit

Permalink
ARROW-17079: Show HTTP status code for unknown S3 errors (#14019)
Browse files Browse the repository at this point in the history
This is the last change I propose to improve our S3 error message.

For certain errors, unfortunately the AWS SDK is doing a poor job in propagating the error and just reports UNKNOWN (see https://github.com/aws/aws-sdk-cpp/blob/1614bce979a201ada1e3436358edb7bd1834b5d6/aws-cpp-sdk-core/source/client/AWSClient.cpp#L77), in these cases the HTTP status code can be an important source to find out what is going wrong (and is also reported by boto3).

This has the downside of cluttering the error message a bit more, but in general this information will be very valuable to diagnose the problem. Given that we now have the API call and the HTTP status error, in general there is good documentation on the internet that helps diagnose the problem.

Before:

> When getting information for key 'test.csv' in bucket 'pcmoritz-test-bucket-arrow-errors': AWS Error UNKNOWN during HeadObject call: No response body.

After:

> When getting information for key 'test.csv' in bucket 'pcmoritz-test-bucket-arrow-errors': AWS Error UNKNOWN **(HTTP status 400)** during HeadObject call: No response body.

Lead-authored-by: Philipp Moritz <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
  • Loading branch information
pcmoritz and pitrou authored Sep 6, 2022
1 parent 3e40cd3 commit a5ecb0f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cpp/src/arrow/filesystem/s3_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ Status ErrorToStatus(const std::string& prefix, const std::string& operation,
// XXX Handle fine-grained error types
// See
// https://sdk.amazonaws.com/cpp/api/LATEST/namespace_aws_1_1_s3.html#ae3f82f8132b619b6e91c88a9f1bde371
return Status::IOError(
prefix, "AWS Error ",
S3ErrorToString(static_cast<Aws::S3::S3Errors>(error.GetErrorType())), " during ",
operation, " operation: ", error.GetMessage());
auto error_type = static_cast<Aws::S3::S3Errors>(error.GetErrorType());
std::stringstream ss;
ss << S3ErrorToString(error_type);
if (error_type == Aws::S3::S3Errors::UNKNOWN) {
ss << " (HTTP status " << static_cast<int>(error.GetResponseCode()) << ")";
}
return Status::IOError(prefix, "AWS Error ", ss.str(), " during ", operation,
" operation: ", error.GetMessage());
}

template <typename ErrorType, typename... Args>
Expand Down

0 comments on commit a5ecb0f

Please sign in to comment.