From cef16a6233aa26003e9e8912eb6c5a7762a318df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Fri, 14 Jun 2024 02:00:47 -0700 Subject: [PATCH] Do not print stack trace Summary: This was missed on the changes from https://github.com/facebook/ktfmt/pull/476, but luckily our internal tests caught it when I tried to sent out a new release. Reviewed By: strulovich Differential Revision: D58528471 fbshipit-source-id: ea4824b295f452b1dc0f7d868664e6792ba07c9c --- .../main/java/com/facebook/ktfmt/cli/Main.kt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt index 8a1ff36f..1b259733 100644 --- a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt +++ b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt @@ -79,9 +79,8 @@ class Main( } fun run(): Int { - val processArgs = ParsedArgs.processArgs(inputArgs) val parsedArgs = - when (processArgs) { + when (val processArgs = ParsedArgs.processArgs(inputArgs)) { is ParseResult.Ok -> processArgs.parsedValue is ParseResult.ShowMessage -> { out.println(processArgs.message) @@ -103,8 +102,7 @@ class Main( val alreadyFormatted = format(null, parsedArgs) if (!alreadyFormatted && parsedArgs.setExitIfChanged) EXIT_CODE_FAILURE else EXIT_CODE_SUCCESS - } catch (e: Exception) { - e.printStackTrace(err) + } catch (_: Exception) { EXIT_CODE_FAILURE } } @@ -116,18 +114,17 @@ class Main( return EXIT_CODE_FAILURE } - val retval = AtomicInteger(EXIT_CODE_SUCCESS) + val returnCode = AtomicInteger(EXIT_CODE_SUCCESS) files.parallelStream().forEach { try { if (!format(it, parsedArgs) && parsedArgs.setExitIfChanged) { - retval.set(EXIT_CODE_FAILURE) + returnCode.set(EXIT_CODE_FAILURE) } - } catch (e: Exception) { - e.printStackTrace(err) - retval.set(EXIT_CODE_FAILURE) + } catch (_: Exception) { + returnCode.set(EXIT_CODE_FAILURE) } } - return retval.get() + return returnCode.get() } /**