Skip to content

Commit

Permalink
move retryable flag to enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Nov 30, 2023
1 parent 72dcf91 commit c11a1c1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ AWSError<CoreErrors> GetErrorForName(const char* errorName)

if (hashCode == CONFLICT_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::CONFLICT), false, false);
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::CONFLICT), RetryableType::NOT_RETRYABLE);
}
else if (hashCode == SERVICE_QUOTA_EXCEEDED_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::SERVICE_QUOTA_EXCEEDED), false, false);
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::SERVICE_QUOTA_EXCEEDED), RetryableType::NOT_RETRYABLE);
}
else if (hashCode == INTERNAL_SERVER_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::INTERNAL_SERVER), true, false);
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::INTERNAL_SERVER), RetryableType::RETRYABLE);
}
else if (hashCode == INVALID_PARAMETER_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::INVALID_PARAMETER), false, false);
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::INVALID_PARAMETER), RetryableType::NOT_RETRYABLE);
}
else if (hashCode == UNPROCESSABLE_ENTITY_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::UNPROCESSABLE_ENTITY), true, false);
return AWSError<CoreErrors>(static_cast<CoreErrors>(AccessAnalyzerErrors::UNPROCESSABLE_ENTITY), RetryableType::RETRYABLE);
}
return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
}
Expand Down
54 changes: 32 additions & 22 deletions src/aws-cpp-sdk-core/include/aws/core/client/AWSError.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ namespace Aws
JSON
};

enum class RetryableType
{
NOT_RETRYABLE,
RETRYABLE,
RETRYABLE_TRHOTTLING
};

/**
* Container for Error enumerations with additional exception information. Name, message, retryable etc....
*/
Expand All @@ -44,39 +51,45 @@ namespace Aws
AWSError()
: m_errorType(),
m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
m_isRetryable(false),
m_errorPayloadType(ErrorPayloadType::NOT_SET),
m_isThrottling(false)
m_retryableType(RetryableType::NOT_RETRYABLE)
{}

/**
* Initializes AWSError object with errorType, exceptionName, message, and retryable flag.
* Initializes AWSError object with errorType, exceptionName, message, and retryable type.
*/
AWSError(ERROR_TYPE errorType,
Aws::String exceptionName,
Aws::String message,
bool isRetryable,
bool isThrottling = false)
bool isRetryable)
: m_errorType(errorType),
m_exceptionName(std::move(exceptionName)),
m_message(std::move(message)),
m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
m_isRetryable(isRetryable),
m_errorPayloadType(ErrorPayloadType::NOT_SET),
m_isThrottling(isThrottling)
m_retryableType(isRetryable? RetryableType::RETRYABLE : RetryableType::NOT_RETRYABLE)
{}

/**
* Initializes AWSError object with errorType and retryable flag. ExceptionName and message are empty.
*/
AWSError(ERROR_TYPE errorType,
bool isRetryable,
bool isThrottling = false) :
m_errorType(errorType),
m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
m_isRetryable(isRetryable),
m_errorPayloadType(ErrorPayloadType::NOT_SET),
m_isThrottling(isThrottling)
bool isRetryable) :
m_errorType(errorType),
m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
m_errorPayloadType(ErrorPayloadType::NOT_SET),
m_retryableType(isRetryable? RetryableType::RETRYABLE : RetryableType::NOT_RETRYABLE)
{}

/**
* Initializes AWSError object with errorType and retryable type. ExceptionName and message are empty.
*/
AWSError(ERROR_TYPE errorType,
RetryableType retryableType) :
m_errorType(errorType),
m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
m_errorPayloadType(ErrorPayloadType::NOT_SET),
m_retryableType(retryableType)
{}

AWSError(AWSError&&) = default;
Expand All @@ -91,11 +104,10 @@ namespace Aws
m_requestId(std::move(rhs.m_requestId)),
m_responseHeaders(std::move(rhs.m_responseHeaders)),
m_responseCode(rhs.m_responseCode),
m_isRetryable(rhs.m_isRetryable),
m_errorPayloadType(rhs.m_errorPayloadType),
m_xmlPayload(std::move(rhs.m_xmlPayload)),
m_jsonPayload(std::move(rhs.m_jsonPayload)),
m_isThrottling(rhs.m_isThrottling)
m_retryableType(rhs.m_retryableType)
{}

template<typename OTHER_ERROR_TYPE>
Expand All @@ -107,11 +119,10 @@ namespace Aws
m_requestId(rhs.m_requestId),
m_responseHeaders(rhs.m_responseHeaders),
m_responseCode(rhs.m_responseCode),
m_isRetryable(rhs.m_isRetryable),
m_errorPayloadType(rhs.m_errorPayloadType),
m_xmlPayload(rhs.m_xmlPayload),
m_jsonPayload(rhs.m_jsonPayload),
m_isThrottling(rhs.m_isThrottling)
m_retryableType(rhs.m_retryableType)
{}

/**
Expand Down Expand Up @@ -177,7 +188,7 @@ namespace Aws
/**
* Returns whether or not this error is eligible for retry.
*/
inline bool ShouldRetry() const { return m_isRetryable; }
inline bool ShouldRetry() const { return m_retryableType == RetryableType::RETRYABLE || m_retryableType == RetryableType::RETRYABLE_TRHOTTLING; }
/**
* Gets the response headers from the http response.
*/
Expand All @@ -201,7 +212,7 @@ namespace Aws
/**
* Return whether or not the error should throttle retry strategies.
*/
inline bool ShouldThrottle() const { return m_isThrottling; }
inline bool ShouldThrottle() const { return m_retryableType == RetryableType::RETRYABLE_TRHOTTLING; }

protected:
inline ErrorPayloadType GetErrorPayloadType() { return m_errorPayloadType; }
Expand Down Expand Up @@ -243,12 +254,11 @@ namespace Aws
Aws::String m_requestId;
Aws::Http::HeaderValueCollection m_responseHeaders;
Aws::Http::HttpResponseCode m_responseCode = Aws::Http::HttpResponseCode::REQUEST_NOT_MADE;
bool m_isRetryable = false;

ErrorPayloadType m_errorPayloadType = ErrorPayloadType::NOT_SET;
Aws::Utils::Xml::XmlDocument m_xmlPayload;
Aws::Utils::Json::JsonValue m_jsonPayload;
bool m_isThrottling;
RetryableType m_retryableType;
};

template<typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,21 @@ because MSVC has a maximum of 122 chained if-else blocks.
#if ($errorCounter % 122 == 0)
#set($elseText = "")
#set ($helperIndex = $errorCounter / 122)
#if ($error.throttling && $error.retryable)
#set($retryableType = "RetryableType::RETRYABLE_TRHOTTLING")
#elseif ($error.retryable)
#set($retryableType = "RetryableType::RETRYABLE")
#else
#set($retryableType = "RetryableType::NOT_RETRYABLE")
#end

static bool GetErrorForNameHelper${helperIndex}(int hashCode, AWSError<CoreErrors>& error)
{
#end
#set($constName = ${ErrorFormatter.formatErrorConstName($error.name)})
${elseText}if (hashCode == ${constName}_HASH)
{
error = AWSError<CoreErrors>(static_cast<CoreErrors>(${metadata.classNamePrefix}Errors::$constName), ${error.retryable}, ${error.throttling});
error = AWSError<CoreErrors>(static_cast<CoreErrors>(${metadata.classNamePrefix}Errors::$constName), ${retryableType});
return true;
}
#set($elseText = "else ")
Expand All @@ -94,10 +101,17 @@ AWSError<CoreErrors> GetErrorForName(const char* errorName)
int hashCode = HashingUtils::HashString(errorName);

#foreach($error in $nonCoreServiceErrors)
#if ($error.throttling && $error.retryable)
#set($retryableType = "RetryableType::RETRYABLE_TRHOTTLING")
#elseif ($error.retryable)
#set($retryableType = "RetryableType::RETRYABLE")
#else
#set($retryableType = "RetryableType::NOT_RETRYABLE")
#end
#set($constName = ${ErrorFormatter.formatErrorConstName($error.name)})
${elseText}if (hashCode == ${constName}_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(${metadata.classNamePrefix}Errors::$constName), ${error.retryable}, ${error.throttling});
return AWSError<CoreErrors>(static_cast<CoreErrors>(${metadata.classNamePrefix}Errors::$constName), ${retryableType});
}
#set($elseText = "else ")
#end
Expand Down

0 comments on commit c11a1c1

Please sign in to comment.