mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
IllegalCommandArgumentException
This commit is contained in:
parent
82de404149
commit
d4c147a8a9
@ -58,7 +58,7 @@ public sealed class CommandExecuteResult {
|
|||||||
/** 执行执行时发生了一个非法参数错误 */
|
/** 执行执行时发生了一个非法参数错误 */
|
||||||
public class IllegalArgument(
|
public class IllegalArgument(
|
||||||
/** 指令执行时发生的错误 */
|
/** 指令执行时发生的错误 */
|
||||||
public override val exception: IllegalArgumentException,
|
public override val exception: IllegalCommandArgumentException,
|
||||||
/** 尝试执行的指令 */
|
/** 尝试执行的指令 */
|
||||||
public override val command: Command,
|
public override val command: Command,
|
||||||
/** 尝试执行的指令名 */
|
/** 尝试执行的指令名 */
|
||||||
@ -180,7 +180,7 @@ public fun CommandExecuteResult.isExecutionException(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.PermissionDenied] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
||||||
@ -192,7 +192,7 @@ public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.CommandNotFound] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
||||||
@ -204,7 +204,7 @@ public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 或 [CommandExecuteResult.CommandNotFound] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed], [CommandExecuteResult.IllegalArgument] 或 [CommandExecuteResult.CommandNotFound] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isFailure(): Boolean {
|
public fun CommandExecuteResult.isFailure(): Boolean {
|
||||||
|
@ -282,6 +282,13 @@ public sealed class AbstractCommandSender : CommandSender, CoroutineScope {
|
|||||||
if (this is CommandSenderOnMessage<*>) {
|
if (this is CommandSenderOnMessage<*>) {
|
||||||
val cause = e.rootCauseOrSelf
|
val cause = e.rootCauseOrSelf
|
||||||
|
|
||||||
|
// TODO: 2020/10/17
|
||||||
|
// CommandArgumentParserException 作为 IllegalCommandArgumentException 不会再进入此函数
|
||||||
|
// 已在
|
||||||
|
// - [console] CommandManagerImpl.commandListener
|
||||||
|
// - [terminal] ConsoleThread.kt
|
||||||
|
// 处理
|
||||||
|
|
||||||
val message = cause
|
val message = cause
|
||||||
.takeIf { it is CommandArgumentParserException }?.message
|
.takeIf { it is CommandArgumentParserException }?.message
|
||||||
?: "${cause::class.simpleName.orEmpty()}: ${cause.message}"
|
?: "${cause::class.simpleName.orEmpty()}: ${cause.message}"
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||||
|
*
|
||||||
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
|
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
|
||||||
|
*
|
||||||
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
|
import net.mamoe.mirai.console.command.descriptor.CommandArgumentParserException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在处理参数时遇到的 _正常_ 错误. 如参数不符合规范, 参数值越界等.
|
||||||
|
*
|
||||||
|
* [message] 将会发送给指令调用方.
|
||||||
|
*
|
||||||
|
* @see CommandArgumentParserException
|
||||||
|
*/
|
||||||
|
public open class IllegalCommandArgumentException : IllegalArgumentException {
|
||||||
|
public constructor() : super()
|
||||||
|
public constructor(message: String?) : super(message)
|
||||||
|
public constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||||
|
public constructor(cause: Throwable?) : super(cause)
|
||||||
|
}
|
@ -11,15 +11,18 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.command.descriptor
|
package net.mamoe.mirai.console.command.descriptor
|
||||||
|
|
||||||
|
import net.mamoe.mirai.console.command.IllegalCommandArgumentException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在解析参数时遇到的 _正常_ 错误. 如参数不符合规范等.
|
* 在解析参数时遇到的 _正常_ 错误. 如参数不符合规范等.
|
||||||
*
|
*
|
||||||
* [message] 将会发送给指令调用方.
|
* [message] 将会发送给指令调用方.
|
||||||
*
|
*
|
||||||
|
* @see IllegalCommandArgumentException
|
||||||
* @see CommandValueArgumentParser
|
* @see CommandValueArgumentParser
|
||||||
* @see CommandValueArgumentParser.illegalArgument
|
* @see CommandValueArgumentParser.illegalArgument
|
||||||
*/
|
*/
|
||||||
public class CommandArgumentParserException : RuntimeException {
|
public class CommandArgumentParserException : IllegalCommandArgumentException {
|
||||||
public constructor() : super()
|
public constructor() : super()
|
||||||
public constructor(message: String?) : super(message)
|
public constructor(message: String?) : super(message)
|
||||||
public constructor(message: String?, cause: Throwable?) : super(message, cause)
|
public constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||||
|
@ -37,7 +37,7 @@ internal suspend fun CommandSender.executeCommandInternal(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
onFailure = { exception ->
|
onFailure = { exception ->
|
||||||
return if (exception is IllegalArgumentException) CommandExecuteResult.IllegalArgument(
|
return if (exception is IllegalCommandArgumentException) CommandExecuteResult.IllegalArgument(
|
||||||
commandName = commandName,
|
commandName = commandName,
|
||||||
command = command,
|
command = command,
|
||||||
exception = exception,
|
exception = exception,
|
||||||
|
Loading…
Reference in New Issue
Block a user