-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat: Increase installation logging granularity and set process exit code properly #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking | |
import picocli.CommandLine.* | ||
import java.io.File | ||
import java.util.logging.Logger | ||
import kotlin.system.exitProcess | ||
|
||
@Command( | ||
name = "install", | ||
|
@@ -44,20 +45,35 @@ internal object InstallCommand : Runnable { | |
}.install(Installer.Apk(apk, packageName)) | ||
} catch (e: Exception) { | ||
logger.severe(e.toString()) | ||
throw e | ||
} | ||
|
||
when (result) { | ||
RootInstallerResult.FAILURE -> | ||
RootInstallerResult.SUCCESS -> | ||
logger.info("Mounted the APK file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Mounting" is an installation method. I think we don't need more granularity than "install" for both cases. Mentioning that it was mounted is not necessary too for the reason that the CLI input already mentions --mount as an installation method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'ite, both
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy w/ RootInstallerResult.FAILURE -> {
logger.severe("Failed to mount the APK file") or want it changed? |
||
RootInstallerResult.FAILURE -> { | ||
logger.severe("Failed to mount the APK file") | ||
is AdbInstallerResult.Failure -> | ||
logger.severe(result.exception.toString()) | ||
else -> | ||
throw Exception() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raising an empty exception doesn't look right to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as explained above - it's for control flow only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, you can probably just return? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like above, we should continue this discussion under the return code chain |
||
} | ||
AdbInstallerResult.Success -> | ||
logger.info("Installed the APK file") | ||
is AdbInstallerResult.Failure -> { | ||
logger.severe("Failed to install the APK file: ${result.exception}") | ||
throw Exception() | ||
} | ||
else -> { | ||
logger.severe("Unknown installation result") | ||
oSumAtrIX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw Exception() | ||
} | ||
} | ||
} | ||
|
||
runBlocking { | ||
deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install() | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally find exceptions ugly/messy code. They introduce nesting and unnecessary blocks of code. Using return values seems simpler for "binary" cases. Exceptions have particular use case for raising messages or multiple kinds of cases not just true or false. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you pefer not to use exceptions for this control flow, then what do you propose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the expected way of returning an exit code for PicoCLI? If so, every subcommand should be subject to this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly no idea what the common there pattern is. |
||
deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install() | ||
} catch (_: Exception) { | ||
exitProcess(1) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import kotlinx.coroutines.runBlocking | |
import picocli.CommandLine.* | ||
import picocli.CommandLine.Help.Visibility.ALWAYS | ||
import java.util.logging.Logger | ||
import kotlin.system.exitProcess | ||
|
||
@Command( | ||
name = "uninstall", | ||
|
@@ -48,19 +49,35 @@ internal object UninstallCommand : Runnable { | |
}.uninstall(packageName) | ||
} catch (e: Exception) { | ||
logger.severe(e.toString()) | ||
throw e | ||
} | ||
|
||
when (result) { | ||
RootInstallerResult.FAILURE -> | ||
RootInstallerResult.SUCCESS -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just noticing code duplication here and in the patch subcommand, possibly extracting into a common function makes sense. |
||
logger.info("Unmounted the patched APK file") | ||
RootInstallerResult.FAILURE -> { | ||
logger.severe("Failed to unmount the patched APK file") | ||
is AdbInstallerResult.Failure -> | ||
throw Exception() | ||
} | ||
AdbInstallerResult.Success -> | ||
logger.info("Uninstalled the patched APK file") | ||
is AdbInstallerResult.Failure -> { | ||
logger.severe(result.exception.toString()) | ||
else -> logger.info("Uninstalled the patched APK file") | ||
throw Exception() | ||
} | ||
else -> { | ||
logger.severe("Unknown uninstallation result") | ||
throw Exception() | ||
} | ||
} | ||
} | ||
|
||
runBlocking { | ||
deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall() | ||
try { | ||
deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall() | ||
} catch (_: Exception) { | ||
exitProcess(1) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we logging when throwing the exception which will be logged again?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't be logged again. The err is rethrown only for the sake of control flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a binary situation, you can use return logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should continue this discussion under the return code chain