Skip to content

Commit 8568ad3

Browse files
authored
[CDK] Always use lower cases for error message regex matching in error translation (#44832)
1 parent 8f12adc commit 8568ad3

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

airbyte-cdk/java/airbyte-cdk/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ corresponds to that version.
174174

175175
| Version | Date | Pull Request | Subject |
176176
|:-----------|:-----------|:-------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------|
177+
| 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. |
177178
| 0.44.16 | 2024-08-22 | [\#44505](https://github.com/airbytehq/airbyte/pull/44505) | Destinations: add sqlgenerator testing for mixed-case stream name |
178179
| 0.44.15 | ?????????? | [\#?????](https://github.com/airbytehq/airbyte/pull/?????) | ????? |
179180
| 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 |

airbyte-cdk/java/airbyte-cdk/core/src/main/kotlin/io/airbyte/cdk/integrations/util/ConnectorExceptionHandler.kt

+10-27
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import io.airbyte.protocol.models.v0.AirbyteMessage
1414
import io.github.oshai.kotlinlogging.KotlinLogging
1515
import java.util.function.Consumer
1616
import java.util.regex.Pattern
17-
import java.util.regex.PatternSyntaxException
1817
import kotlin.system.exitProcess
1918
import org.jetbrains.annotations.VisibleForTesting
2019

@@ -33,22 +32,11 @@ data class ConnectorErrorProfile(
3332
val sampleInternalMessage: String,
3433
val referenceLinks: List<String> = emptyList(),
3534
) {
35+
val regexPattern: Pattern = Pattern.compile(regexMatchingPattern, Pattern.CASE_INSENSITIVE)
3636
init {
37-
require(isValidRegex(regexMatchingPattern)) {
38-
"regexMatchingPattern is not a valid regular expression string"
39-
}
4037
require(externalMessage.isNotBlank()) { "externalMessage must not be blank" }
4138
require(sampleInternalMessage.isNotBlank()) { "sampleInternalMessage must not be blank" }
4239
}
43-
44-
private fun isValidRegex(regexString: String): Boolean {
45-
return try {
46-
Pattern.compile(regexString)
47-
true
48-
} catch (e: PatternSyntaxException) {
49-
false
50-
}
51-
}
5240
}
5341

5442
/**
@@ -144,10 +132,8 @@ open class ConnectorExceptionHandler {
144132
*/
145133
open fun translateConnectorSpecificErrorMessage(e: Throwable?): String? {
146134
if (e == null) return null
147-
for (error in connectorErrorDictionary) {
148-
if (e.message?.lowercase()?.matches(error.regexMatchingPattern.toRegex())!!)
149-
return error.externalMessage
150-
}
135+
for (error in connectorErrorDictionary) if (error.regexPattern.matcher(e.message).matches())
136+
return error.externalMessage
151137
return null
152138
}
153139

@@ -179,13 +165,10 @@ open class ConnectorExceptionHandler {
179165
return true
180166
}
181167

182-
for (error in connectorErrorDictionary) {
183-
if (
184-
error.failureType == failureType &&
185-
e!!.message?.matches(error.regexMatchingPattern.toRegex())!!
186-
)
187-
return true
188-
}
168+
for (error in connectorErrorDictionary) if (
169+
error.failureType == failureType && error.regexPattern.matcher(e!!.message).matches()
170+
)
171+
return true
189172
return false
190173
}
191174

@@ -194,14 +177,14 @@ open class ConnectorExceptionHandler {
194177
* a known transient exception, a config exception, or an exception whose error messages have been
195178
* stored as part of the error profile in the error dictionary.
196179
* */
180+
@VisibleForTesting
197181
private fun isRecognizableError(e: Throwable?): Boolean {
198182
if (e?.message == null) return false
199183
if (e is TransientErrorException || e is ConfigErrorException) {
200184
return true
201185
}
202-
for (error in connectorErrorDictionary) {
203-
if (e.message!!.matches(error.regexMatchingPattern.toRegex())) return true
204-
}
186+
for (error in connectorErrorDictionary) if (error.regexPattern.matcher(e.message).matches())
187+
return true
205188
return false
206189
}
207190
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.44.16
1+
version=0.44.17

0 commit comments

Comments
 (0)