From 4526f71cc76ded4f72c827f9151028c3ca20bbf7 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 16 Nov 2020 12:26:14 +0800 Subject: [PATCH] Let the console know the full stacktrace for the IllegalArgument --- .../src/command/IllegalCommandArgumentException.kt | 3 +++ frontend/mirai-console-terminal/src/ConsoleThread.kt | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/command/IllegalCommandArgumentException.kt b/backend/mirai-console/src/command/IllegalCommandArgumentException.kt index 461f701d8..adc2d785b 100644 --- a/backend/mirai-console/src/command/IllegalCommandArgumentException.kt +++ b/backend/mirai-console/src/command/IllegalCommandArgumentException.kt @@ -18,6 +18,9 @@ import net.mamoe.mirai.console.command.descriptor.CommandArgumentParserException * * [message] 将会发送给指令调用方. * + * 如果指令调用方是 [ConsoleCommandSender], + * 还会将 [cause], [suppressedExceptions] 发送给 [ConsoleCommandSender] (如果存在) + * * @see CommandArgumentParserException */ public open class IllegalCommandArgumentException : IllegalArgumentException { diff --git a/frontend/mirai-console-terminal/src/ConsoleThread.kt b/frontend/mirai-console-terminal/src/ConsoleThread.kt index 575b28be9..1417943f9 100644 --- a/frontend/mirai-console-terminal/src/ConsoleThread.kt +++ b/frontend/mirai-console-terminal/src/ConsoleThread.kt @@ -62,7 +62,16 @@ internal fun startupConsoleThread() { is Success -> { } is IllegalArgument -> { - result.exception.message?.let { consoleLogger.warning(it) } ?: kotlin.run { + result.exception.message?.let { msg -> + val err = result.exception + if ((err.suppressed?.size ?: 0) != 0) { + // 该 IllegalArgument 错误还存在其他附加错误 + consoleLogger.warning(result.exception) + } else { + consoleLogger.warning(msg) + err.cause?.let { consoleLogger.warning(it) } + } + } ?: kotlin.run { consoleLogger.warning(result.exception) } }