diff options
author | pacien | 2018-08-01 16:03:37 +0200 |
---|---|---|
committer | pacien | 2018-08-01 16:03:37 +0200 |
commit | ac154eb8927ba7ace334213b8cd2a7607d11ddfa (patch) | |
tree | 498165d1add6edc719135a02507651911126148b /app/src/main/java/org/pacien | |
parent | 36683767bab31c70a42a1f5812e63634b0f52e88 (diff) | |
download | tincapp-ac154eb8927ba7ace334213b8cd2a7607d11ddfa.tar.gz |
Include exit code in error message
Diffstat (limited to 'app/src/main/java/org/pacien')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Executor.kt | 10 |
1 files changed, 6 insertions, 4 deletions
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 { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | return runAsyncTask { | 59 | return runAsyncTask { |
60 | when (wait(pid)) { | 60 | val exitCode = wait(pid) |
61 | when (exitCode) { | ||
61 | SUCCESS -> Unit | 62 | SUCCESS -> Unit |
62 | FAILED -> throw CommandExecutionException("Process terminated abnormally.") | 63 | FAILED -> throw CommandExecutionException("Process terminated abnormally.") |
63 | else -> throw CommandExecutionException("Non-zero exit status code.") | 64 | else -> throw CommandExecutionException("Non-zero exit status code ($exitCode).") |
64 | } | 65 | } |
65 | } | 66 | } |
66 | } | 67 | } |
@@ -73,8 +74,9 @@ internal object Executor { | |||
73 | 74 | ||
74 | fun call(cmd: Command): CompletableFuture<List<String>> = run(cmd).let { process -> | 75 | fun call(cmd: Command): CompletableFuture<List<String>> = run(cmd).let { process -> |
75 | supplyAsyncTask<List<String>> { | 76 | supplyAsyncTask<List<String>> { |
76 | if (process.waitFor() == 0) read(process.inputStream) | 77 | val exitCode = process.waitFor() |
77 | else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status.") | 78 | if (exitCode == 0) read(process.inputStream) |
79 | else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status ($exitCode).") | ||
78 | } | 80 | } |
79 | } | 81 | } |
80 | 82 | ||