From 4f6c60f029487ddbfaabfcc29101a2c39d9959e2 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 17 Dec 2020 10:08:31 -0800 Subject: Transform broken repo error message to be more helpful (#1251) (cherry picked from commit 0396bf92a9a15bcdac8b9fc71f6b34afc949ab41) Signed-off-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/git/BaseGitActivity.kt | 39 ++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt index 5248d259..0e8a2523 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt @@ -70,19 +70,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { GitOp.BREAK_OUT_OF_DETACHED -> BreakOutOfDetached(this) GitOp.RESET -> ResetToRemoteOperation(this) } - return op.executeAfterAuthentication(GitSettings.authMode).mapError { throwable -> - val err = rootCauseException(throwable) - if (err.message?.contains("cannot open additional channels") == true) { - GitSettings.useMultiplexing = false - SSHException(DisconnectReason.TOO_MANY_CONNECTIONS, "The server does not support multiple Git operations per SSH session. Please try again, a slower fallback mode will be used.") - } else if (err is TransportException && err.disconnectReason == DisconnectReason.HOST_KEY_NOT_VERIFIABLE) { - SSHException(DisconnectReason.HOST_KEY_NOT_VERIFIABLE, - "WARNING: The remote host key has changed. If this is expected, please go to Git server settings and clear the saved host key." - ) - } else { - err - } - } + return op.executeAfterAuthentication(GitSettings.authMode).mapError(::transformGitError) } fun finishOnSuccessHandler(@Suppress("UNUSED_PARAMETER") nothing: Unit) { @@ -113,6 +101,31 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { } } + /** + * Takes the result of [launchGitOperation] and applies any necessary transformations + * on the [throwable] returned from it + */ + private fun transformGitError(throwable: Throwable): Throwable { + val err = rootCauseException(throwable) + return when { + err.message?.contains("cannot open additional channels") == true -> { + GitSettings.useMultiplexing = false + SSHException(DisconnectReason.TOO_MANY_CONNECTIONS, "The server does not support multiple Git operations per SSH session. Please try again, a slower fallback mode will be used.") + } + err.message?.contains("int org.eclipse.jgit.lib.AnyObjectId.w1") == true -> { + IllegalStateException("Your local repository appears to be an incomplete Git clone, please delete and re-clone from settings") + } + err is TransportException && err.disconnectReason == DisconnectReason.HOST_KEY_NOT_VERIFIABLE -> { + SSHException(DisconnectReason.HOST_KEY_NOT_VERIFIABLE, + "WARNING: The remote host key has changed. If this is expected, please go to Git server settings and clear the saved host key." + ) + } + else -> { + err + } + } + } + /** * Check if a given [Throwable] is the result of an error caused by the user cancelling the * operation. -- cgit v1.2.3