From ed1d431a1f3ebaf0654590c4032edcdaade5bab3 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Mon, 12 Feb 2024 04:25:27 +0000 Subject: [PATCH] Improved to output error details when bucket check fails --- src/s3fs.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index aefd110..d5d7332 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4398,6 +4398,18 @@ static bool check_endpoint_error(const char* pbody, size_t len, std::string& exp return true; } +static bool check_error_message(const char* pbody, size_t len, std::string& message) +{ + message.clear(); + if(!pbody){ + return false; + } + if(!simple_parse_xml(pbody, len, "Message", message)){ + return false; + } + return true; +} + // [NOTE] // This function checks if the bucket is accessible when s3fs starts. // @@ -4505,18 +4517,23 @@ static int s3fs_check_service() // check errors(after retrying) if(0 > res && responseCode != 200 && responseCode != 301){ + // parse error message if existed + std::string errMessage; + const std::string* body = s3fscurl.GetBodyData(); + check_error_message(body->c_str(), body->size(), errMessage); + if(responseCode == 400){ - S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bad Request(host=%s)", s3host.c_str()); + S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bad Request(host=%s, message=%s)", s3host.c_str(), errMessage.c_str()); }else if(responseCode == 403){ - S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Invalid Credentials(host=%s)", s3host.c_str()); + S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Invalid Credentials(host=%s, message=%s)", s3host.c_str(), errMessage.c_str()); }else if(responseCode == 404){ if(mount_prefix.empty()){ - S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bucket or directory not found(host=%s)", s3host.c_str()); + S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bucket or directory not found(host=%s, message=%s)", s3host.c_str(), errMessage.c_str()); }else{ - S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bucket or directory(%s) not found(host=%s) - You may need to specify the compat_dir option.", mount_prefix.c_str(), s3host.c_str()); + S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bucket or directory(%s) not found(host=%s, message=%s) - You may need to specify the compat_dir option.", mount_prefix.c_str(), s3host.c_str(), errMessage.c_str()); } }else{ - S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Unable to connect(host=%s)", s3host.c_str()); + S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Unable to connect(host=%s, message=%s)", s3host.c_str(), errMessage.c_str()); } return EXIT_FAILURE; }