Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CDK] Always use lower cases for error message regex matching in error translation #44832

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code review
  • Loading branch information
theyueli committed Aug 27, 2024
commit a195b2bb82afa31ce7cbce139377f3ff9bfae6c3
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data class ConnectorErrorProfile(
val externalMessage: String,
val sampleInternalMessage: String,
val referenceLinks: List<String> = emptyList(),
var regexPattern: Pattern = Pattern.compile(".*"),
) {
init {
require(isValidRegex(regexMatchingPattern)) {
Expand All @@ -43,7 +44,7 @@ data class ConnectorErrorProfile(

private fun isValidRegex(regexString: String): Boolean {
return try {
Pattern.compile(regexString)
regexPattern = Pattern.compile(regexString, Pattern.CASE_INSENSITIVE)
true
} catch (e: PatternSyntaxException) {
false
Expand Down Expand Up @@ -144,10 +145,8 @@ open class ConnectorExceptionHandler {
*/
open fun translateConnectorSpecificErrorMessage(e: Throwable?): String? {
if (e == null) return null
for (error in connectorErrorDictionary) {
if (e.message?.lowercase()?.matches(error.regexMatchingPattern.lowercase().toRegex())!!)
return error.externalMessage
}
for (error in connectorErrorDictionary)
if (error.regexPattern.matcher(e.message).matches()) return error.externalMessage
return null
}

Expand Down Expand Up @@ -179,16 +178,9 @@ open class ConnectorExceptionHandler {
return true
}

for (error in connectorErrorDictionary) {
if (
error.failureType == failureType &&
e!!
.message
?.lowercase()
?.matches(error.regexMatchingPattern.lowercase().toRegex())!!
)
return true
}
for (error in connectorErrorDictionary) if (error.failureType == failureType &&
error.regexPattern.matcher(e!!.message).matches())
return true
return false
}

Expand All @@ -197,15 +189,15 @@ open class ConnectorExceptionHandler {
* a known transient exception, a config exception, or an exception whose error messages have been
* stored as part of the error profile in the error dictionary.
* */
@VisibleForTesting
private fun isRecognizableError(e: Throwable?): Boolean {
if (e?.message == null) return false
if (e is TransientErrorException || e is ConfigErrorException) {
return true
}
for (error in connectorErrorDictionary) {
if (e.message!!.lowercase().matches(error.regexMatchingPattern.lowercase().toRegex()))
for (error in connectorErrorDictionary)
if (error.regexPattern.matcher(e.message).matches())
return true
}
return false
}
}
Loading