Skip to content

Commit

Permalink
Improved to output error details when bucket check fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Feb 12, 2024
1 parent a7186b6 commit f5a4710
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f5a4710

Please sign in to comment.