1
1
/* Copyright (c) 2024 Airbyte, Inc., all rights reserved. */
2
2
package io.airbyte.cdk.check
3
3
4
+ import io.airbyte.cdk.ConfigErrorException
4
5
import io.airbyte.cdk.Operation
5
- import io.airbyte.cdk.command.*
6
+ import io.airbyte.cdk.command.ConfigurationJsonObjectBase
7
+ import io.airbyte.cdk.command.ConfigurationJsonObjectSupplier
8
+ import io.airbyte.cdk.command.SourceConfiguration
9
+ import io.airbyte.cdk.command.SourceConfigurationFactory
6
10
import io.airbyte.cdk.discover.MetadataQuerier
11
+ import io.airbyte.cdk.output.ExceptionClassifier
7
12
import io.airbyte.cdk.output.OutputConsumer
8
- import io.airbyte.cdk.util.ApmTraceUtils
9
13
import io.airbyte.protocol.models.v0.AirbyteConnectionStatus
10
14
import io.airbyte.protocol.models.v0.AirbyteErrorTraceMessage
11
15
import io.github.oshai.kotlinlogging.KotlinLogging
12
16
import io.micronaut.context.annotation.Requires
13
17
import jakarta.inject.Singleton
14
- import java.sql.SQLException
15
- import org.apache.commons.lang3.exception.ExceptionUtils
16
18
17
19
@Singleton
18
20
@Requires(property = Operation .PROPERTY , value = " check" )
@@ -22,6 +24,7 @@ class CheckOperation<T : ConfigurationJsonObjectBase>(
22
24
val configFactory : SourceConfigurationFactory <T , out SourceConfiguration >,
23
25
val metadataQuerierFactory : MetadataQuerier .Factory <SourceConfiguration >,
24
26
val outputConsumer : OutputConsumer ,
27
+ val exceptionClassifier : ExceptionClassifier ,
25
28
) : Operation {
26
29
private val log = KotlinLogging .logger {}
27
30
@@ -34,37 +37,15 @@ class CheckOperation<T : ConfigurationJsonObjectBase>(
34
37
val config: SourceConfiguration = configFactory.make(pojo)
35
38
log.info { " Connecting for config check." }
36
39
metadataQuerierFactory.session(config).use { connectionCheck(it) }
37
- } catch (e: SQLException ) {
38
- log.debug(e) { " SQLException while checking config." }
39
- val message: String =
40
- listOfNotNull(
41
- e.sqlState?.let { " State code: $it " },
42
- e.errorCode.takeIf { it != 0 }?.let { " Error code: $it " },
43
- e.message?.let { " Message: $it " },
44
- )
45
- .joinToString(separator = " ; " )
46
- ApmTraceUtils .addExceptionToTrace(e)
47
- outputConsumer.accept(
48
- AirbyteErrorTraceMessage ()
49
- .withFailureType(AirbyteErrorTraceMessage .FailureType .CONFIG_ERROR )
50
- .withMessage(message)
51
- .withInternalMessage(e.toString())
52
- .withStackTrace(ExceptionUtils .getStackTrace(e)),
53
- )
54
- outputConsumer.accept(
55
- AirbyteConnectionStatus ()
56
- .withMessage(message)
57
- .withStatus(AirbyteConnectionStatus .Status .FAILED ),
58
- )
59
- log.info { " Config check failed." }
60
- return
61
40
} catch (e: Exception ) {
62
41
log.debug(e) { " Exception while checking config." }
63
- ApmTraceUtils .addExceptionToTrace(e)
64
- outputConsumer.acceptTraceOnConfigError(e)
42
+ val errorTraceMessage: AirbyteErrorTraceMessage = exceptionClassifier.handle(e)
43
+ outputConsumer.accept(errorTraceMessage)
44
+ val connectionStatusMessage: String =
45
+ String .format(COMMON_EXCEPTION_MESSAGE_TEMPLATE , errorTraceMessage.message)
65
46
outputConsumer.accept(
66
47
AirbyteConnectionStatus ()
67
- .withMessage(String .format( COMMON_EXCEPTION_MESSAGE_TEMPLATE , e.message) )
48
+ .withMessage(connectionStatusMessage )
68
49
.withStatus(AirbyteConnectionStatus .Status .FAILED ),
69
50
)
70
51
log.info { " Config check failed." }
@@ -101,9 +82,9 @@ class CheckOperation<T : ConfigurationJsonObjectBase>(
101
82
}
102
83
}
103
84
if (n == 0 ) {
104
- throw RuntimeException (" Discovered zero tables." )
85
+ throw ConfigErrorException (" Discovered zero tables." )
105
86
} else {
106
- throw RuntimeException (" Unable to query any of the $n discovered table(s)." )
87
+ throw ConfigErrorException (" Unable to query any of the $n discovered table(s)." )
107
88
}
108
89
}
109
90
0 commit comments