From ac154eb8927ba7ace334213b8cd2a7607d11ddfa Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 1 Aug 2018 16:03:37 +0200 Subject: Include exit code in error message --- app/src/main/java/org/pacien/tincapp/commands/Executor.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt index 6fe7c4c..7630b61 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt @@ -57,10 +57,11 @@ internal object Executor { } return runAsyncTask { - when (wait(pid)) { + val exitCode = wait(pid) + when (exitCode) { SUCCESS -> Unit FAILED -> throw CommandExecutionException("Process terminated abnormally.") - else -> throw CommandExecutionException("Non-zero exit status code.") + else -> throw CommandExecutionException("Non-zero exit status code ($exitCode).") } } } @@ -73,8 +74,9 @@ internal object Executor { fun call(cmd: Command): CompletableFuture> = run(cmd).let { process -> supplyAsyncTask> { - if (process.waitFor() == 0) read(process.inputStream) - else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status.") + val exitCode = process.waitFor() + if (exitCode == 0) read(process.inputStream) + else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status ($exitCode).") } } -- cgit v1.2.3