Skip to content

Commit ee0d8df

Browse files
committed
feat: provide (un)installer with failure exit code
- exit InstallCommand/UninstallCommand with exit code 1 on detected command failures or thrown exceptions; log where appropriate - fixes #362
1 parent b065ef4 commit ee0d8df

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

src/main/kotlin/app/revanced/cli/command/utility/InstallCommand.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
77
import picocli.CommandLine.*
88
import java.io.File
99
import java.util.logging.Logger
10+
import kotlin.system.exitProcess
1011

1112
@Command(
1213
name = "install",
@@ -30,7 +31,7 @@ internal object InstallCommand : Runnable {
3031

3132
@Option(
3233
names = ["-m", "--mount"],
33-
description = ["Mount the supplied APK file over the app with the supplied package name."],
34+
description = ["Mount the supplied APK file over the app with the given package name."],
3435
)
3536
private var packageName: String? = null
3637

@@ -44,24 +45,35 @@ internal object InstallCommand : Runnable {
4445
}.install(Installer.Apk(apk, packageName))
4546
} catch (e: Exception) {
4647
logger.severe(e.toString())
47-
return
48+
throw e
4849
}
4950

5051
when (result) {
5152
RootInstallerResult.SUCCESS ->
5253
logger.info("Mounted the APK file")
53-
RootInstallerResult.FAILURE ->
54+
RootInstallerResult.FAILURE -> {
5455
logger.severe("Failed to mount the APK file")
56+
throw Exception()
57+
}
5558
AdbInstallerResult.Success ->
5659
logger.info("Installed the APK file")
57-
is AdbInstallerResult.Failure ->
60+
is AdbInstallerResult.Failure -> {
5861
logger.severe(result.exception.toString())
59-
else -> logger.severe("Unknown installation result")
62+
throw Exception()
63+
}
64+
else -> {
65+
logger.severe("Unknown installation result")
66+
throw Exception()
67+
}
6068
}
6169
}
6270

6371
runBlocking {
64-
deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install()
72+
try {
73+
deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install()
74+
} catch (_: Exception) {
75+
exitProcess(1)
76+
}
6577
}
6678
}
6779
}

src/main/kotlin/app/revanced/cli/command/utility/UninstallCommand.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.coroutines.runBlocking
1010
import picocli.CommandLine.*
1111
import picocli.CommandLine.Help.Visibility.ALWAYS
1212
import java.util.logging.Logger
13+
import kotlin.system.exitProcess
1314

1415
@Command(
1516
name = "uninstall",
@@ -48,24 +49,35 @@ internal object UninstallCommand : Runnable {
4849
}.uninstall(packageName)
4950
} catch (e: Exception) {
5051
logger.severe(e.toString())
51-
return
52+
throw e
5253
}
5354

5455
when (result) {
5556
RootInstallerResult.SUCCESS ->
5657
logger.info("Unmounted the patched APK file")
57-
RootInstallerResult.FAILURE ->
58+
RootInstallerResult.FAILURE -> {
5859
logger.severe("Failed to unmount the patched APK file")
60+
throw Exception()
61+
}
5962
AdbInstallerResult.Success ->
6063
logger.info("Uninstalled the patched APK file")
61-
is AdbInstallerResult.Failure ->
64+
is AdbInstallerResult.Failure -> {
6265
logger.severe(result.exception.toString())
63-
else -> logger.severe("Unknown uninstallation result")
66+
throw Exception()
67+
}
68+
else -> {
69+
logger.severe("Unknown uninstallation result")
70+
throw Exception()
71+
}
6472
}
6573
}
6674

6775
runBlocking {
68-
deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall()
76+
try {
77+
deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall()
78+
} catch (_: Exception) {
79+
exitProcess(1)
80+
}
6981
}
7082
}
7183
}

0 commit comments

Comments
 (0)