From b5117289a26a263f8b82b0475bf8ec7ff81fc43c Mon Sep 17 00:00:00 2001 From: Amanjeet Singh Date: Wed, 29 Jan 2025 13:53:53 +0530 Subject: [PATCH] fix: properly pipe the error --- .../src/main/kotlin/util/CommandLineUtils.kt | 4 +-- .../main/kotlin/util/LocalSimulatorUtils.kt | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/maestro-ios-driver/src/main/kotlin/util/CommandLineUtils.kt b/maestro-ios-driver/src/main/kotlin/util/CommandLineUtils.kt index aa1880f929..fd5493adcd 100644 --- a/maestro-ios-driver/src/main/kotlin/util/CommandLineUtils.kt +++ b/maestro-ios-driver/src/main/kotlin/util/CommandLineUtils.kt @@ -24,7 +24,7 @@ object CommandLineUtils { } else { ProcessBuilder(*parts.toTypedArray()) .redirectOutput(nullFile) - .redirectError(nullFile) + .redirectError(ProcessBuilder.Redirect.PIPE) } processBuilder.environment().putAll(params) @@ -42,7 +42,7 @@ object CommandLineUtils { .readUtf8() logger.error("Process failed with exit code ${process.exitValue()}") - logger.error(processOutput) + logger.error("Error output $processOutput") throw IllegalStateException(processOutput) } diff --git a/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt b/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt index a6f7d5cc27..7eb59748d0 100644 --- a/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt +++ b/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt @@ -164,15 +164,24 @@ object LocalSimulatorUtils { fun terminate(deviceId: String, bundleId: String) { // Ignore error return: terminate will fail if the app is not running - runCommand( - listOf( - "xcrun", - "simctl", - "terminate", - deviceId, - bundleId + logger.info("[Start] Terminating app $bundleId") + runCatching { + runCommand( + listOf( + "xcrun", + "simctl", + "terminate", + deviceId, + bundleId + ) ) - ) + }.onFailure { + if (it.message?.contains("found nothing to terminate") == false) { + logger.info("The bundle $bundleId is already terminated") + throw it + } + } + logger.info("[Done] Terminating app $bundleId") } private fun isAppRunning(deviceId: String, bundleId: String): Boolean {