Skip to content

Commit 03fc3a3

Browse files
authored
[console] Unwrap InvocationTargetException when executing commands (#2258)
1 parent 5bf9fdf commit 03fc3a3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mirai-console/backend/mirai-console/src/internal/command/CommandManagerImpl.kt

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import net.mamoe.mirai.message.data.Message
2828
import net.mamoe.mirai.message.data.toMessageChain
2929
import net.mamoe.mirai.utils.MiraiLogger
3030
import net.mamoe.mirai.utils.childScope
31+
import java.lang.reflect.InvocationTargetException
3132
import java.util.concurrent.locks.ReentrantLock
3233
import kotlin.coroutines.CoroutineContext
3334

@@ -168,6 +169,12 @@ internal suspend fun executeCommandImpl(
168169
CommandExecuteResult.Success(resolved.callee, call, resolved)
169170
} catch (e: CommandArgumentParserException) {
170171
CommandExecuteResult.IllegalArgument(e, resolved.callee, call, resolved)
172+
} catch (e: InvocationTargetException) {
173+
when (val target = e.cause) {
174+
is CommandArgumentParserException -> CommandExecuteResult.IllegalArgument(target, resolved.callee, call, resolved)
175+
null -> CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved)
176+
else -> CommandExecuteResult.ExecutionFailed(target, resolved.callee, call, resolved)
177+
}
171178
} catch (e: Throwable) {
172179
CommandExecuteResult.ExecutionFailed(e, resolved.callee, call, resolved)
173180
}

0 commit comments

Comments
 (0)