File tree 4 files changed +36
-27
lines changed
main/kotlin/io/airbyte/cdk/output
test/kotlin/io/airbyte/cdk/output
toolkits/extract-jdbc/src/main/kotlin/io/airbyte/cdk/output
4 files changed +36
-27
lines changed Original file line number Diff line number Diff line change @@ -22,24 +22,12 @@ class DefaultExceptionClassifier(
22
22
) : ExceptionClassifier {
23
23
24
24
override fun classify (e : Throwable ): ConnectorError ? {
25
- return when (val connectorErrorException: ConnectorErrorException ? = unwind(e)) {
26
- is ConfigErrorException -> ConfigError (connectorErrorException.message!! )
27
- is TransientErrorException -> TransientError (connectorErrorException.message!! )
28
- is SystemErrorException -> SystemError (connectorErrorException.message)
29
- null -> null
25
+ val unwound: Throwable ? = ExceptionClassifier .unwind(e) { it is ConnectorErrorException }
26
+ return when (unwound) {
27
+ is ConfigErrorException -> ConfigError (unwound.message!! )
28
+ is TransientErrorException -> TransientError (unwound.message!! )
29
+ is SystemErrorException -> SystemError (unwound.message)
30
+ else -> null
30
31
}
31
32
}
32
-
33
- /* * Recursively walks the causes of [e] and returns the last [ConnectorErrorException]. */
34
- fun unwind (e : Throwable ): ConnectorErrorException ? {
35
- var connectorErrorException: ConnectorErrorException ? = null
36
- var unwound: Throwable ? = e
37
- while (unwound != null ) {
38
- if (unwound is ConnectorErrorException ) {
39
- connectorErrorException = unwound
40
- }
41
- unwound = unwound.cause
42
- }
43
- return connectorErrorException
44
- }
45
33
}
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ interface ExceptionClassifier : Ordered {
15
15
val orderValue: Int
16
16
17
17
override fun getOrder (): Int = orderValue
18
+
19
+ companion object {
20
+ fun unwind (e : Throwable , stopUnwind : (Throwable ) -> Boolean ): Throwable ? {
21
+ var unwound = e
22
+ while (! stopUnwind(unwound)) {
23
+ unwound = unwound.cause ? : return null
24
+ }
25
+ return unwound
26
+ }
27
+ }
18
28
}
19
29
20
30
/* * Each [ConnectorError] subtype corresponds to a [AirbyteErrorTraceMessage.FailureType]. */
@@ -54,10 +64,8 @@ interface RuleBasedExceptionClassifier<T : RuleBasedExceptionClassifier.Rule> :
54
64
55
65
override fun classify (e : Throwable ): ConnectorError ? {
56
66
for (rule in rules) {
57
- if (! rule.matches(e)) {
58
- continue
59
- }
60
- val message: String = rule.output ? : e.message ? : e.toString()
67
+ val match: Throwable = ExceptionClassifier .unwind(e, rule::matches) ? : continue
68
+ val message: String = rule.output ? : match.message ? : match.toString()
61
69
val firstLine: String = if (rule.group == null ) message else " ${rule.group} : $message "
62
70
val lines: List <String > = listOf (firstLine) + rule.referenceLinks
63
71
val displayMessage: String = lines.joinToString(separator = " \n " )
Original file line number Diff line number Diff line change @@ -80,4 +80,16 @@ class RegexExceptionClassifierTest {
80
80
classifier.classify(RuntimeException (" barbaz" )),
81
81
)
82
82
}
83
+
84
+ @Test
85
+ fun testRecursiveRuleOrdering () {
86
+ Assertions .assertEquals(
87
+ ConfigError (" grouped: has foo\n https://www.youtube.com/watch?v=xvFZjo5PgG0" ),
88
+ classifier.classify(RuntimeException (" quux" , RuntimeException (" foobarbaz" ))),
89
+ )
90
+ Assertions .assertEquals(
91
+ TransientError (" barbaz" ),
92
+ classifier.classify(RuntimeException (" quux" , RuntimeException (" barbaz" ))),
93
+ )
94
+ }
83
95
}
Original file line number Diff line number Diff line change @@ -29,15 +29,16 @@ class JdbcExceptionClassifier(
29
29
}
30
30
31
31
override fun classify (e : Throwable ): ConnectorError ? {
32
- if (e !is SQLException ) return null
32
+ var match: SQLException =
33
+ ExceptionClassifier .unwind(e) { it is SQLException } as ? SQLException ? : return null
33
34
val decoratedMessage: String =
34
35
listOfNotNull(
35
- e .sqlState?.let { " State code: $it " },
36
- e .errorCode.takeIf { it != 0 }?.let { " Error code: $it " },
37
- e .message?.let { " Message: $it " },
36
+ match .sqlState?.let { " State code: $it " },
37
+ match .errorCode.takeIf { it != 0 }?.let { " Error code: $it " },
38
+ match .message?.let { " Message: $it " },
38
39
)
39
40
.joinToString(separator = " ; " )
40
- val decoratedException = SQLException (decoratedMessage, e .sqlState, e .errorCode)
41
+ val decoratedException = SQLException (decoratedMessage, match .sqlState, match .errorCode)
41
42
val ruleBasedMatch: ConnectorError ? = super .classify(decoratedException)
42
43
if (ruleBasedMatch != null ) {
43
44
return ruleBasedMatch
You can’t perform that action at this time.
0 commit comments