diff --git a/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java b/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java index a273d01b0..529efb8c3 100644 --- a/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java +++ b/che-core-git-impl-jgit/src/main/java/org/eclipse/che/git/impl/jgit/JGitConnection.java @@ -131,6 +131,7 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; +import javax.net.ssl.SSLHandshakeException; import java.io.File; import java.io.FileOutputStream; import java.io.FilenameFilter; @@ -211,6 +212,8 @@ class JGitConnection implements GitConnection { private static final String MESSAGE_COMMIT_NOT_POSSIBLE = "Commit is not possible because repository state is '%s'"; private static final String MESSAGE_AMEND_NOT_POSSIBLE = "Amend is not possible because repository state is '%s'"; + private static final String FILE_NAME_TOO_LONG_ERROR_PREFIX = "File name too long"; + private static final Logger LOG = LoggerFactory.getLogger(JGitConnection.class); private Git git; @@ -459,7 +462,8 @@ public void clone(CloneRequest request) throws GitException, UnauthorizedExcepti if (removeIfFailed) { deleteRepositoryFolder(); } - throw new GitException(exception.getMessage(), exception); + String message = generateExceptionMessage(exception); + throw new GitException(message, exception); } } @@ -568,7 +572,7 @@ public void fetch(FetchRequest request) throws GitException, UnauthorizedExcepti } else if ("Nothing to fetch.".equals(exception.getMessage())) { return; } else { - errorMessage = exception.getMessage(); + errorMessage = generateExceptionMessage(exception); } throw new GitException(errorMessage, exception); } @@ -908,7 +912,7 @@ public PullResponse pull(PullRequest request) throws GitException, UnauthorizedE if (exception.getMessage().equals("Invalid remote: " + remoteName)) { errorMessage = ERROR_NO_REMOTE_REPOSITORY; } else { - errorMessage = exception.getMessage(); + errorMessage = generateExceptionMessage(exception); } throw new GitException(errorMessage, exception); } @@ -949,7 +953,8 @@ public PushResponse push(PushRequest request) throws GitException, UnauthorizedE if ("origin: not found.".equals(exception.getMessage())) { throw new GitException(ERROR_NO_REMOTE_REPOSITORY, exception); } else { - throw new GitException(exception.getMessage(), exception); + String message = generateExceptionMessage(exception); + throw new GitException(message, exception); } } } @@ -1445,7 +1450,8 @@ public boolean accept(File dir) { } } } catch (IOException exception) { - throw new GitException(exception.getMessage(), exception); + String message = generateExceptionMessage(exception); + throw new GitException(message, exception); } } @@ -1597,4 +1603,42 @@ private String cleanRemoteName(String branchName) throws GitException { } return returnName; } + + /** + * Method for generate exception message. The default logic return message from the error. + * It also check if the type of the message is for SSL or in case that the error + * start with "file name to long" then it raise the relevant message + * + * @param error + * throwable error + * @return exception message + */ + private String generateExceptionMessage(Throwable error) { + String message = error.getMessage(); + while (error.getCause() != null) { + //if e caused by an SSLHandshakeException - replace thrown message with a hardcoded message + if (error.getCause() instanceof SSLHandshakeException) { + message = "The system is not configured to trust the security certificate provided by the Git server"; + break; + } else if (error.getCause() instanceof IOException) { + // Security fix - error message should not include complete local file path on the target system + // Error message for example - File name too long (path /xx/xx/xx/xx/xx/xx/xx/xx /, working dir /xx/xx/xx) + if (message != null && message.startsWith(FILE_NAME_TOO_LONG_ERROR_PREFIX)) { + try { + String repoPath = repository.getWorkTree().getCanonicalPath(); + int startIndex = message.indexOf(repoPath); + int endIndex = message.indexOf(","); + if (startIndex > -1 && endIndex > -1) { + message = FILE_NAME_TOO_LONG_ERROR_PREFIX + " " + message.substring(startIndex + repoPath.length(), endIndex); + } + break; + } catch (IOException e) { + //Hide exception as it is only needed for this message generation + } + } + } + error = error.getCause(); + } + return message; + } }