Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling when additional sources/destinations cannot be read #8031

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public AirbyteGithubStore(final String baseUrl, final Duration timeout) {
public List<StandardDestinationDefinition> getLatestDestinations() throws InterruptedException {
try {
return YamlListToStandardDefinitions.toStandardDestinationDefinitions(getFile(DESTINATION_DEFINITION_LIST_LOCATION_PATH));
} catch (final IOException e) {
} catch (final Throwable e) {
LOGGER.warn(
"Unable to retrieve latest Destination list from Github. Using the list bundled with Airbyte. This warning is expected if this Airbyte cluster does not have internet access.",
e);
Expand All @@ -64,7 +64,7 @@ public List<StandardDestinationDefinition> getLatestDestinations() throws Interr
public List<StandardSourceDefinition> getLatestSources() throws InterruptedException {
try {
return YamlListToStandardDefinitions.toStandardSourceDefinitions(getFile(SOURCE_DEFINITION_LIST_LOCATION_PATH));
} catch (final IOException e) {
} catch (final Throwable e) {
LOGGER.warn(
"Unable to retrieve latest Source list from Github. Using the list bundled with Airbyte. This warning is expected if this Airbyte cluster does not have internet access.",
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,56 @@ public void setUp() {
githubStore = AirbyteGithubStore.test(webServer.url("/").toString(), TIMEOUT);
}

@Nested
@DisplayName("when the additional definitions file is unusable, badly formatted, or cannot be retrieved due to errors")
class FileUnusable {

@Test
void testGetLatestSourcesWithNonJson() throws InterruptedException {
final var nonjsonBody = "irrelevant text";
final var nonjsonResponse = new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "text/plain; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody(nonjsonBody);
webServer.enqueue(nonjsonResponse);
assertEquals(Collections.emptyList(), githubStore.getLatestSources());
}

@Test
void testGetLatestSourcesWithWrongSchemaJson() throws InterruptedException {
final var jsonBody = "{ json: 'validButWrongFormat' }";
final var jsonResponse = new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody(jsonBody);
webServer.enqueue(jsonResponse);
assertEquals(Collections.emptyList(), githubStore.getLatestSources());
}

@Test
void testGetLatestDestinationsWithNonJson() throws InterruptedException {
final var nonjsonBody = "irrelevant text";
final var nonjsonResponse = new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "text/plain; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody(nonjsonBody);
webServer.enqueue(nonjsonResponse);
assertEquals(Collections.emptyList(), githubStore.getLatestDestinations());
}

@Test
void testGetLatestDestinationsWithWrongSchemaJson() throws InterruptedException {
final var jsonBody = "{ json: 'validButWrongFormat' }";
final var jsonResponse = new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody(jsonBody);
webServer.enqueue(jsonResponse);
assertEquals(Collections.emptyList(), githubStore.getLatestDestinations());
}

}

@Nested
@DisplayName("when there is no internet")
class NoInternet {
Expand Down