fix: Update error handling for git connect (#11070)

* Update error handling for git connect

* Add testcase for git generic error
This commit is contained in:
Abhijeet 2022-02-11 16:17:02 +05:30 committed by GitHub
parent 85cc3f3497
commit 6f7691b6aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 7 deletions

View File

@ -2,6 +2,6 @@ package com.appsmith.git.constants;
public class Constraint {
public static final int MAX_COMMIT_LOGS = 100;
public static final int REMOTE_TIMEOUT_MILLIS = 20000;
public static final int LOCAL_TIMEOUT_MILLIS = 5000;
public static final int REMOTE_TIMEOUT_MILLIS = 60000;
public static final int LOCAL_TIMEOUT_MILLIS = 10000;
}

View File

@ -135,6 +135,7 @@ public enum AppsmithError {
GIT_PULL_CONFLICTS(400, 4047, "Merge conflicts found during the pull operation: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_PULL_CONFLICT),
SSH_KEY_GENERATION_ERROR(500, 5015, "Failed to generate SSH keys, please contact Appsmith support for more details", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null),
GIT_UPSTREAM_CHANGES(400, 4048, "Looks like there are pending upstream changes. To prevent you from losing history, we will pull the changes and push them to your repo.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES),
GIT_GENERIC_ERROR(504, 5016, "Git command execution error: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null),
;
private final Integer httpErrorCode;

View File

@ -675,7 +675,7 @@ public class GitServiceCEImpl implements GitServiceCE {
gitApplicationMetadata.getGitAuth().getPublicKey()
)
.onErrorResume(error -> {
log.error("Error while cloning the remote repo, {}", error.getMessage());
log.error("Error while cloning the remote repo, ", error);
return addAnalyticsForGitOperation(
AnalyticsEvents.GIT_CONNECT.getEventName(),
application,
@ -690,7 +690,10 @@ public class GitServiceCEImpl implements GitServiceCE {
if (error instanceof InvalidRemoteException) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, error.getMessage()));
}
return Mono.error(new AppsmithException(AppsmithError.GIT_EXECUTION_TIMEOUT));
if (error instanceof TimeoutException) {
return Mono.error(new AppsmithException(AppsmithError.GIT_EXECUTION_TIMEOUT));
}
return Mono.error(new AppsmithException(AppsmithError.GIT_GENERIC_ERROR, error.getMessage()));
});
});
return Mono.zip(

View File

@ -455,6 +455,23 @@ public class GitServiceTest {
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void connectApplicationToGit_cloneException_throwGitException() throws IOException {
Mockito.when(gitExecutor.cloneApplication(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
.thenReturn(Mono.error(new Exception("error message")));
GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile);
Mono<Application> applicationMono = gitService.connectApplicationToGit(gitConnectedApplication.getId(), gitConnectDTO, "baseUrl");
StepVerifier
.create(applicationMono)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException
&& throwable.getMessage().equals(AppsmithError.GIT_GENERIC_ERROR.getMessage("error message")))
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void connectApplicationToGit_WithEmptyPublishedPages_CloneSuccess() throws IOException {
@ -2295,11 +2312,10 @@ public class GitServiceTest {
.map(Organization::getId)
.block();
GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitImportRepo.git", testUserProfile);
GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitImportRepoCancelledMidway.git", testUserProfile);
GitAuth gitAuth = gitService.generateSSHKey().block();
ApplicationJson applicationJson = createAppJson(filePath).block();
applicationJson.getExportedApplication().setName("testGitImportRepoCancelledMidway");
applicationJson.getDatasourceList().get(0).setName("db-auth-testGitImportRepo");
String pluginId = pluginRepository.findByPackageName("mongo-plugin").block().getId();
@ -2341,7 +2357,7 @@ public class GitServiceTest {
assertThat(application.getGitApplicationMetadata()).isNotNull();
assertThat(application.getGitApplicationMetadata().getBranchName()).isEqualTo("defaultBranch");
assertThat(application.getGitApplicationMetadata().getDefaultBranchName()).isEqualTo("defaultBranch");
assertThat(application.getGitApplicationMetadata().getRemoteUrl()).isEqualTo("git@github.com:test/testGitImportRepo.git");
assertThat(application.getGitApplicationMetadata().getRemoteUrl()).isEqualTo("git@github.com:test/testGitImportRepoCancelledMidway.git");
assertThat(application.getGitApplicationMetadata().getIsRepoPrivate()).isEqualTo(true);
assertThat(application.getGitApplicationMetadata().getGitAuth().getPublicKey()).isEqualTo(gitAuth.getPublicKey());