1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 13:03:35 +08:00

[core] Include more details in error message to help debug.

This commit is contained in:
Karlatemp 2022-12-08 23:44:30 +08:00
parent d655af2c0b
commit c52e99dd87
No known key found for this signature in database
GPG Key ID: BA173CA2B9956C59
3 changed files with 8 additions and 6 deletions
mirai-core/src/commonMain/kotlin/contact

View File

@ -183,7 +183,9 @@ internal abstract class CommonGroupImpl constructor(
private val messageProtocolStrategy: MessageProtocolStrategy<GroupImpl> = GroupMessageProtocolStrategy(this.cast())
override suspend fun quit(): Boolean {
check(botPermission != MemberPermission.OWNER) { "An owner cannot quit from a owning group" }
check(botPermission != MemberPermission.OWNER) {
"Failed to quit $id because bot is the owner"
}
if (!bot.groups.delegate.remove(this)) {
return false
@ -193,7 +195,7 @@ internal abstract class CommonGroupImpl constructor(
ProfileService.GroupMngReq(bot.client, this@CommonGroupImpl.id), 5000, 2
)
check(response.errorCode == 0) {
"Group.quit failed: $response".also {
"Group($id).quit failed: $response".also {
bot.groups.delegate.add(this@CommonGroupImpl.castUp())
}
}

View File

@ -184,7 +184,7 @@ internal class NormalMemberImpl constructor(
// Note: when member not found, result is still true.
if (response.ret == 255) error("Operation too fast") // https://github.com/mamoe/mirai/issues/1503
check(response.success) { "kick failed: ${response.ret}" }
check(response.success) { "kick member $id of group ${group.id} failed: ${response.ret}" }
group.members.delegate.removeAll { it.id == this@NormalMemberImpl.id }
@ -235,7 +235,7 @@ internal class NormalMemberImpl constructor(
internal fun Member.checkBotPermissionHighest(operationName: String) {
check(group.botPermission == MemberPermission.OWNER) {
throw PermissionDeniedException(
"`$operationName` operation requires the OWNER permission, while bot has ${group.botPermission}",
"`$operationName` operation for member $id requires the OWNER permission, while bot has ${group.botPermission} in group ${group.id}",
)
}
}
@ -243,7 +243,7 @@ internal fun Member.checkBotPermissionHighest(operationName: String) {
internal fun Member.checkBotPermissionHigherThanThis(operationName: String) {
check(group.botPermission > this.permission) {
throw PermissionDeniedException(
"`$operationName` operation requires a higher permission, while " +
"`$operationName` operation for member $id of group ${group.id} requires a higher permission, while " +
"${group.botPermission} < ${this.permission}",
)
}

View File

@ -57,7 +57,7 @@ internal class StrangerImpl(
"Stranger ${this.id} had already been deleted"
}
bot.network.sendAndExpect(StrangerList.DelStranger(bot.client, this@StrangerImpl), 5000, 2).also {
check(it.isSuccess) { "delete Stranger failed: ${it.result}" }
check(it.isSuccess) { "delete Stranger $id failed: ${it.result}" }
}
}