Improved error message obtention
Improved error message obtention by looking into causes instead of the top level exception
This commit is contained in:
parent
cf136a35d0
commit
88bee8dfcd
@ -0,0 +1,4 @@
|
|||||||
|
package com.jetpackduba.gitnuro.exceptions
|
||||||
|
|
||||||
|
class CommandExecutionFailed(msg: String, cause: Exception) : GitnuroException(msg, cause) {
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
package com.jetpackduba.gitnuro.exceptions
|
package com.jetpackduba.gitnuro.exceptions
|
||||||
|
|
||||||
abstract class GitnuroException(msg: String) : RuntimeException(msg)
|
abstract class GitnuroException(msg: String, cause: Exception? = null) : Exception(msg, cause)
|
@ -1,6 +1,7 @@
|
|||||||
package com.jetpackduba.gitnuro.git
|
package com.jetpackduba.gitnuro.git
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.di.TabScope
|
import com.jetpackduba.gitnuro.di.TabScope
|
||||||
|
import com.jetpackduba.gitnuro.exceptions.GitnuroException
|
||||||
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
||||||
import com.jetpackduba.gitnuro.git.log.FindCommitUseCase
|
import com.jetpackduba.gitnuro.git.log.FindCommitUseCase
|
||||||
import com.jetpackduba.gitnuro.logging.printError
|
import com.jetpackduba.gitnuro.logging.printError
|
||||||
@ -143,8 +144,11 @@ class TabState @Inject constructor(
|
|||||||
|
|
||||||
val containsCancellation = exceptionContainsCancellation(ex)
|
val containsCancellation = exceptionContainsCancellation(ex)
|
||||||
|
|
||||||
if (!containsCancellation)
|
if (!containsCancellation) {
|
||||||
errorsManager.addError(newErrorNow(ex, null, ex.message.orEmpty()))
|
val innerException = getInnerException(ex)
|
||||||
|
|
||||||
|
errorsManager.addError(newErrorNow(innerException, null, innerException.message.orEmpty()))
|
||||||
|
}
|
||||||
|
|
||||||
printError(TAG, ex.message.orEmpty(), ex)
|
printError(TAG, ex.message.orEmpty(), ex)
|
||||||
} finally {
|
} finally {
|
||||||
@ -163,6 +167,20 @@ class TabState @Inject constructor(
|
|||||||
return job
|
return job
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getInnerException(ex: Exception): Exception {
|
||||||
|
return if (ex is GitnuroException) {
|
||||||
|
ex
|
||||||
|
} else {
|
||||||
|
val cause = ex.cause
|
||||||
|
|
||||||
|
if (cause != null && cause is Exception) {
|
||||||
|
getInnerException(cause)
|
||||||
|
} else {
|
||||||
|
ex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun exceptionContainsCancellation(ex: Throwable?): Boolean {
|
private fun exceptionContainsCancellation(ex: Throwable?): Boolean {
|
||||||
return when (ex) {
|
return when (ex) {
|
||||||
null -> false
|
null -> false
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jetpackduba.gitnuro
|
package com.jetpackduba.gitnuro
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.managers.ShellManager
|
||||||
import com.jetpackduba.gitnuro.preferences.initPreferencesPath
|
import com.jetpackduba.gitnuro.preferences.initPreferencesPath
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jetpackduba.gitnuro.managers
|
package com.jetpackduba.gitnuro.managers
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.exceptions.CommandExecutionFailed
|
||||||
import com.jetpackduba.gitnuro.logging.printError
|
import com.jetpackduba.gitnuro.logging.printError
|
||||||
import com.jetpackduba.gitnuro.logging.printLog
|
import com.jetpackduba.gitnuro.logging.printLog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -79,7 +80,12 @@ class ShellManager @Inject constructor() : IShellManager {
|
|||||||
|
|
||||||
override fun runCommandProcess(command: List<String>): Process {
|
override fun runCommandProcess(command: List<String>): Process {
|
||||||
printLog(TAG, "runCommandProcess: " + command.joinToString(" "))
|
printLog(TAG, "runCommandProcess: " + command.joinToString(" "))
|
||||||
|
try {
|
||||||
return ProcessBuilder(command).start()
|
return ProcessBuilder(command).start()
|
||||||
|
// return ProcessBuilder(command).start()
|
||||||
|
} catch (ex: IOException) {
|
||||||
|
throw CommandExecutionFailed(ex.message.orEmpty(), ex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user