From a5ecb0ff0774805b0f912e231eaedf42e7194c36 Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Tue, 6 Sep 2022 06:46:36 -0700 Subject: [PATCH] ARROW-17079: Show HTTP status code for unknown S3 errors (#14019) 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 Co-authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- cpp/src/arrow/filesystem/s3_internal.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/filesystem/s3_internal.h b/cpp/src/arrow/filesystem/s3_internal.h index 093fdc7ca4577..c6e6349ba2cf8 100644 --- a/cpp/src/arrow/filesystem/s3_internal.h +++ b/cpp/src/arrow/filesystem/s3_internal.h @@ -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(error.GetErrorType())), " during ", - operation, " operation: ", error.GetMessage()); + auto error_type = static_cast(error.GetErrorType()); + std::stringstream ss; + ss << S3ErrorToString(error_type); + if (error_type == Aws::S3::S3Errors::UNKNOWN) { + ss << " (HTTP status " << static_cast(error.GetResponseCode()) << ")"; + } + return Status::IOError(prefix, "AWS Error ", ss.str(), " during ", operation, + " operation: ", error.GetMessage()); } template