Skip to content

Commit a53b947

Browse files
authored
Migrating InvalidCursorException -> ConfigErrorException (#18995)
* Migrate InvalidCursorInfo -> ConfigErrorException
1 parent 633531a commit a53b947

File tree

3 files changed

+45
-57
lines changed

3 files changed

+45
-57
lines changed

airbyte-integrations/connectors/source-postgres/src/test/java/io/airbyte/integrations/source/postgres/PostgresSourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.common.collect.Lists;
2020
import com.google.common.collect.Sets;
21+
import io.airbyte.commons.exceptions.ConfigErrorException;
2122
import io.airbyte.commons.io.IOs;
2223
import io.airbyte.commons.json.Jsons;
2324
import io.airbyte.commons.string.Strings;
@@ -26,7 +27,6 @@
2627
import io.airbyte.db.factory.DSLContextFactory;
2728
import io.airbyte.db.factory.DatabaseDriver;
2829
import io.airbyte.db.jdbc.JdbcUtils;
29-
import io.airbyte.integrations.source.relationaldb.InvalidCursorException;
3030
import io.airbyte.protocol.models.AirbyteCatalog;
3131
import io.airbyte.protocol.models.AirbyteMessage;
3232
import io.airbyte.protocol.models.AirbyteStream;
@@ -526,7 +526,7 @@ public void tableWithInvalidCursorShouldThrowException() throws Exception {
526526
new ConfiguredAirbyteCatalog().withStreams(Collections.singletonList(tableWithInvalidCursorType));
527527

528528
final Throwable throwable = catchThrowable(() -> MoreIterators.toSet(new PostgresSource().read(config, configuredAirbyteCatalog, null)));
529-
assertThat(throwable).isInstanceOf(InvalidCursorException.class)
529+
assertThat(throwable).isInstanceOf(ConfigErrorException.class)
530530
.hasMessageContaining(
531531
"The following tables have invalid columns selected as cursor, please select a column with a well-defined ordering as a cursor. {tableName='public.test_table', cursorColumnName='id', cursorSqlType=OTHER}");
532532
} finally {

airbyte-integrations/connectors/source-relational-db/src/main/java/io/airbyte/integrations/source/relationaldb/AbstractDbSource.java

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.JsonNode;
1010
import com.google.common.base.Preconditions;
1111
import com.google.common.collect.Lists;
12+
import io.airbyte.commons.exceptions.ConfigErrorException;
1213
import io.airbyte.commons.exceptions.ConnectionErrorException;
1314
import io.airbyte.commons.features.EnvVariableFeatureFlags;
1415
import io.airbyte.commons.features.FeatureFlags;
@@ -26,7 +27,7 @@
2627
import io.airbyte.integrations.base.AirbyteStreamNameNamespacePair;
2728
import io.airbyte.integrations.base.AirbyteTraceMessageUtility;
2829
import io.airbyte.integrations.base.Source;
29-
import io.airbyte.integrations.source.relationaldb.InvalidCursorException.InvalidCursorInfo;
30+
import io.airbyte.integrations.source.relationaldb.InvalidCursorInfoUtil.InvalidCursorInfo;
3031
import io.airbyte.integrations.source.relationaldb.models.DbState;
3132
import io.airbyte.integrations.source.relationaldb.state.StateManager;
3233
import io.airbyte.integrations.source.relationaldb.state.StateManagerFactory;
@@ -142,56 +143,42 @@ public AirbyteCatalog discover(final JsonNode config) throws Exception {
142143
*/
143144
@Override
144145
public AutoCloseableIterator<AirbyteMessage> read(final JsonNode config,
145-
final ConfiguredAirbyteCatalog catalog,
146-
final JsonNode state)
147-
throws Exception {
148-
try {
149-
final StateManager stateManager =
150-
StateManagerFactory.createStateManager(getSupportedStateType(config),
151-
deserializeInitialState(state, config), catalog);
152-
final Instant emittedAt = Instant.now();
153-
154-
final Database database = createDatabaseInternal(config);
155-
156-
final Map<String, TableInfo<CommonField<DataType>>> fullyQualifiedTableNameToInfo =
157-
discoverWithoutSystemTables(database)
158-
.stream()
159-
.collect(Collectors.toMap(t -> String.format("%s.%s", t.getNameSpace(), t.getName()),
160-
Function
161-
.identity()));
162-
163-
validateCursorFieldForIncrementalTables(fullyQualifiedTableNameToInfo, catalog);
164-
165-
final List<AutoCloseableIterator<AirbyteMessage>> incrementalIterators =
166-
getIncrementalIterators(database, catalog, fullyQualifiedTableNameToInfo, stateManager,
167-
emittedAt);
168-
final List<AutoCloseableIterator<AirbyteMessage>> fullRefreshIterators =
169-
getFullRefreshIterators(database, catalog, fullyQualifiedTableNameToInfo, stateManager,
170-
emittedAt);
171-
final List<AutoCloseableIterator<AirbyteMessage>> iteratorList = Stream
172-
.of(incrementalIterators, fullRefreshIterators)
173-
.flatMap(Collection::stream)
174-
.collect(Collectors.toList());
175-
176-
return AutoCloseableIterators
177-
.appendOnClose(AutoCloseableIterators.concatWithEagerClose(iteratorList), () -> {
178-
LOGGER.info("Closing database connection pool.");
179-
Exceptions.toRuntime(this::close);
180-
LOGGER.info("Closed database connection pool.");
181-
});
182-
} catch (final Exception exception) {
183-
if (isConfigError(exception)) {
184-
AirbyteTraceMessageUtility.emitConfigErrorTrace(exception, exception.getMessage());
185-
}
186-
throw exception;
187-
}
188-
}
146+
final ConfiguredAirbyteCatalog catalog,
147+
final JsonNode state)
148+
throws Exception {
149+
final StateManager stateManager =
150+
StateManagerFactory.createStateManager(getSupportedStateType(config),
151+
deserializeInitialState(state, config), catalog);
152+
final Instant emittedAt = Instant.now();
153+
154+
final Database database = createDatabaseInternal(config);
155+
156+
final Map<String, TableInfo<CommonField<DataType>>> fullyQualifiedTableNameToInfo =
157+
discoverWithoutSystemTables(database)
158+
.stream()
159+
.collect(Collectors.toMap(t -> String.format("%s.%s", t.getNameSpace(), t.getName()),
160+
Function
161+
.identity()));
162+
163+
validateCursorFieldForIncrementalTables(fullyQualifiedTableNameToInfo, catalog);
164+
165+
final List<AutoCloseableIterator<AirbyteMessage>> incrementalIterators =
166+
getIncrementalIterators(database, catalog, fullyQualifiedTableNameToInfo, stateManager,
167+
emittedAt);
168+
final List<AutoCloseableIterator<AirbyteMessage>> fullRefreshIterators =
169+
getFullRefreshIterators(database, catalog, fullyQualifiedTableNameToInfo, stateManager,
170+
emittedAt);
171+
final List<AutoCloseableIterator<AirbyteMessage>> iteratorList = Stream
172+
.of(incrementalIterators, fullRefreshIterators)
173+
.flatMap(Collection::stream)
174+
.collect(Collectors.toList());
189175

190-
private boolean isConfigError(final Exception exception) {
191-
// For now, enhanced error details should only be shown for InvalidCursorException. In the future,
192-
// enhanced error messages will exist for
193-
// additional error types.
194-
return exception instanceof InvalidCursorException;
176+
return AutoCloseableIterators
177+
.appendOnClose(AutoCloseableIterators.concatWithEagerClose(iteratorList), () -> {
178+
LOGGER.info("Closing database connection pool.");
179+
Exceptions.toRuntime(this::close);
180+
LOGGER.info("Closed database connection pool.");
181+
});
195182
}
196183

197184
private void validateCursorFieldForIncrementalTables(
@@ -230,7 +217,8 @@ private void validateCursorFieldForIncrementalTables(
230217
}
231218

232219
if (!tablesWithInvalidCursor.isEmpty()) {
233-
throw new InvalidCursorException(tablesWithInvalidCursor);
220+
throw new ConfigErrorException(
221+
InvalidCursorInfoUtil.getInvalidCursorConfigMessage(tablesWithInvalidCursor)) ;
234222
}
235223
}
236224

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import java.util.List;
88
import java.util.stream.Collectors;
99

10-
public class InvalidCursorException extends RuntimeException {
10+
public class InvalidCursorInfoUtil {
1111

12-
public InvalidCursorException(final List<InvalidCursorInfo> tablesWithInvalidCursor) {
13-
super("The following tables have invalid columns selected as cursor, please select a column with a well-defined ordering as a cursor. "
12+
public static String getInvalidCursorConfigMessage(final List<InvalidCursorInfo> tablesWithInvalidCursor) {
13+
return "The following tables have invalid columns selected as cursor, please select a column with a well-defined ordering as a cursor. "
1414
+ tablesWithInvalidCursor.stream().map(InvalidCursorInfo::toString)
15-
.collect(Collectors.joining(",")));
15+
.collect(Collectors.joining(","));
1616
}
1717

1818
public record InvalidCursorInfo(String tableName, String cursorColumnName, String cursorSqlType) {

0 commit comments

Comments
 (0)