Skip to content

Commit

Permalink
[CDK] Always use lower cases for error message regex matching in erro…
Browse files Browse the repository at this point in the history
…r translation (#44832)
  • Loading branch information
theyueli authored Aug 28, 2024
1 parent 8f12adc commit 8568ad3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
1 change: 1 addition & 0 deletions airbyte-cdk/java/airbyte-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ corresponds to that version.

| Version | Date | Pull Request | Subject |
|:-----------|:-----------|:-------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.44.17 | 2024-08-27 | [\#44832](https://github.com/airbytehq/airbyte/pull/44832) | Fix issues where some error messages with upper cases do not get matched by the error translation framework. |
| 0.44.16 | 2024-08-22 | [\#44505](https://github.com/airbytehq/airbyte/pull/44505) | Destinations: add sqlgenerator testing for mixed-case stream name |
| 0.44.15 | ?????????? | [\#?????](https://github.com/airbytehq/airbyte/pull/?????) | ????? |
| 0.44.14 | 2024-08-19 | [\#42503](https://github.com/airbytehq/airbyte/pull/42503) | Destinations (refreshes) - correctly detect existing raw/final table of the correct generation during truncate sync |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.airbyte.protocol.models.v0.AirbyteMessage
import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.function.Consumer
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
import kotlin.system.exitProcess
import org.jetbrains.annotations.VisibleForTesting

Expand All @@ -33,22 +32,11 @@ data class ConnectorErrorProfile(
val sampleInternalMessage: String,
val referenceLinks: List<String> = emptyList(),
) {
val regexPattern: Pattern = Pattern.compile(regexMatchingPattern, Pattern.CASE_INSENSITIVE)
init {
require(isValidRegex(regexMatchingPattern)) {
"regexMatchingPattern is not a valid regular expression string"
}
require(externalMessage.isNotBlank()) { "externalMessage must not be blank" }
require(sampleInternalMessage.isNotBlank()) { "sampleInternalMessage must not be blank" }
}

private fun isValidRegex(regexString: String): Boolean {
return try {
Pattern.compile(regexString)
true
} catch (e: PatternSyntaxException) {
false
}
}
}

/**
Expand Down Expand Up @@ -144,10 +132,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.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,13 +165,10 @@ open class ConnectorExceptionHandler {
return true
}

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

Expand All @@ -194,14 +177,14 @@ 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!!.matches(error.regexMatchingPattern.toRegex())) return true
}
for (error in connectorErrorDictionary) if (error.regexPattern.matcher(e.message).matches())
return true
return false
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.44.16
version=0.44.17

0 comments on commit 8568ad3

Please sign in to comment.