From c3ec63207cbcb4b2adcfbef8574680edffa020fd Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Sun, 23 Jul 2017 23:07:28 -0700 Subject: [PATCH] Made ktlint print RuleExecutionException stacktrace when in --debug mode --- .../main/kotlin/com/github/shyiko/ktlint/Main.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt index b4f293094f..a1427dfa70 100644 --- a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt +++ b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt @@ -222,11 +222,16 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s fun lintErrorFrom(e: Exception): LintError = when (e) { is ParseException -> LintError(e.line, e.col, "", - "Not a valid Kotlin file (${e.message?.toLowerCase()})") - is RuleExecutionException -> + "Not a valid Kotlin file (${e.message?.toLowerCase()})") + is RuleExecutionException -> { + if (debug) { + System.err.println("[DEBUG] Internal Error (${e.ruleId})") + e.printStackTrace(System.err) + } LintError(e.line, e.col, "", "Internal Error (${e.ruleId}). " + - "Please create a ticket at https://github.com/shyiko/ktlint/issue " + - "(if possible, provide the source code that triggered an error)") + "Please create a ticket at https://github.com/shyiko/ktlint/issue " + + "(if possible, provide the source code that triggered an error)") + } else -> throw e } val tripped = AtomicBoolean()