summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-12-17 10:08:31 -0800
committerGitHub <noreply@github.com>2020-12-17 23:38:31 +0530
commit0396bf92a9a15bcdac8b9fc71f6b34afc949ab41 (patch)
tree8ee134e25daa155c427de3a99ad5ad483e565db9
parent5a3395040cab74903c95eb5d97308451d051ac96 (diff)
Transform broken repo error message to be more helpful (#1251)
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt39
2 files changed, 27 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6799816c..9e00a3e7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- On Android 11, Autofill will use the new [inline autofill](https://developer.android.com/guide/topics/text/ime-autofill#configure-provider) UI that integrates Autofill results into your keyboard app.
- Invalid `.gpg-id` files can now be fixed automatically by deleting them and then trying to create a new password.
+- Suggest users to re-clone repository when it is deemed to be broken
### Fixed
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt
index 558f60a2..8b288d00 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt
@@ -72,19 +72,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) {
@@ -116,6 +104,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.
*/