Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Announcements.get(fid) 出现 kotlinx.serialization.MissingFieldException: Field 'msg' #2509

Closed
ForteScarlet opened this issue Feb 16, 2023 · 5 comments · Fixed by #2512
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Milestone

Comments

@ForteScarlet
Copy link

问题描述

当通过 Announcements.get(fid) 获取指定公告的时候出现反序列化异常

复现

val bot = BotFactory.newBot(0, "").alsoLogin()
val announcements = bot.getGroup(...)!!.announcements
announcements.asFlow().collect { announcement ->
    // Caused by: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing
    announcements.get(announcement.fid)
}

mirai-core 版本

2.14.0

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

2023-02-16 15:21:22 I/Bot 2240189254: Bot login successful.
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:90)
	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:95)
	at net.mamoe.mirai.utils.JsonStructKt.loadAs(JsonStruct.kt:26)
	at net.mamoe.mirai.utils.JsonStructKt.loadAs$default(JsonStruct.kt:25)
	at net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.getGroupAnnouncement(AnnouncementsImpl.kt:302)
	at net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol$getGroupAnnouncement$1.invokeSuspend(AnnouncementsImpl.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:93)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.ByteBufferChannel.resumeClosed(ByteBufferChannel.kt:2156)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.ByteBufferChannel.close(ByteBufferChannel.kt:136)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.CoroutinesKt$launchChannel$1.invoke(Coroutines.kt:145)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.CoroutinesKt$launchChannel$1.invoke(Coroutines.kt:144)
	at kotlinx.coroutines.InvokeOnCompletion.invoke(JobSupport.kt:1392)
	at kotlinx.coroutines.JobSupport.notifyCompletion(JobSupport.kt:1520)
	at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:323)
	at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:240)
	at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:906)
	at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:863)
	at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:828)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Caused by: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing
	at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
	at net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement.<init>(GroupAnnouncement.kt:40)
	at net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement$$serializer.deserialize(GroupAnnouncement.kt:40)
	at net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement$$serializer.deserialize(GroupAnnouncement.kt:40)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70)
	... 27 more

网络日志

No response

补充信息

测试用群公告如图:

image

@Him188
Copy link
Member

Him188 commented Feb 16, 2023

确认fid正确吗,是获取这个公告就必然出现,还是只是有时候会?

@Him188 Him188 added t:bug 类型: bug N 优先级: 一般 z:wait-for-reply 状态: 等待回复 s:core 子系统: mirai-core labels Feb 16, 2023
@Him188 Him188 added this to the Backlog milestone Feb 16, 2023
@ForteScarlet
Copy link
Author

ForteScarlet commented Feb 16, 2023

确认fid正确吗

以示例代码中的表现,我是直接通过获取到的公告列表循环并获取fid的,没有手写的情况,应该不会出错

是获取这个公告就必然出现,还是只是有时候会

我将测试代码改成如下:

val announcements = bot.getGroup(703454734)!!.announcements

    announcements.asFlow().collect { announcement ->
        try {
            logger.info("success: {}", announcements.get(announcement.fid))
        } catch (e: Throwable) {
            logger.error("failure. announcement: {}", announcement)
            logger.error("e: {}", e.toString())
        }
    }

得到的日志如下:

2023-02-16 19:19:25.068 ERROR [DefaultDispatcher-worker-2] announcements-test.emit(21): failure. announcement: OnlineAnnouncementImpl(group=Group(703454734), senderId=1149159218, sender=NormalMember(1149159218), content=这是一个置顶公告, parameters=AnnouncementParameters(image=null, sendToNewMember=true, isPinned=true, showEditCard=false, showPopup=true, requireConfirmation=true), fid=0edeed29000000002dd8ed636aec0300, allConfirmed=false, confirmedMembersCount=0, publicationTime=1676531757)
2023-02-16 19:19:25.069 ERROR [DefaultDispatcher-worker-2] announcements-test.emit(22): e: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
2023-02-16 19:19:25.168 ERROR [DefaultDispatcher-worker-6] announcements-test.emit(21): failure. announcement: OnlineAnnouncementImpl(group=Group(703454734), senderId=1149159218, sender=NormalMember(1149159218), content=这是手机发布的公告, parameters=AnnouncementParameters(image=null, sendToNewMember=false, isPinned=false, showEditCard=false, showPopup=false, requireConfirmation=false), fid=0edeed29000000006010ee63cefc0900, allConfirmed=false, confirmedMembersCount=0, publicationTime=1676546144)
2023-02-16 19:19:25.169 ERROR [DefaultDispatcher-worker-6] announcements-test.emit(22): e: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
2023-02-16 19:19:25.265 ERROR [DefaultDispatcher-worker-5] announcements-test.emit(21): failure. announcement: OnlineAnnouncementImpl(group=Group(703454734), senderId=1149159218, sender=NormalMember(1149159218), content=这是带图片的公告, parameters=AnnouncementParameters(image=null, sendToNewMember=false, isPinned=false, showEditCard=false, showPopup=false, requireConfirmation=false), fid=0edeed29000000004010ee633ca70100, allConfirmed=false, confirmedMembersCount=0, publicationTime=1676546112)
2023-02-16 19:19:25.266 ERROR [DefaultDispatcher-worker-5] announcements-test.emit(22): e: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
2023-02-16 19:19:25.407 ERROR [DefaultDispatcher-worker-1] announcements-test.emit(21): failure. announcement: OnlineAnnouncementImpl(group=Group(703454734), senderId=1149159218, sender=NormalMember(1149159218), content=这是弹窗公告, parameters=AnnouncementParameters(image=null, sendToNewMember=false, isPinned=false, showEditCard=false, showPopup=true, requireConfirmation=false), fid=0edeed29000000002610ee634bb20c00, allConfirmed=false, confirmedMembersCount=0, publicationTime=1676546086)
2023-02-16 19:19:25.407 ERROR [DefaultDispatcher-worker-1] announcements-test.emit(22): e: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
2023-02-16 19:19:25.505 ERROR [DefaultDispatcher-worker-4] announcements-test.emit(21): failure. announcement: OnlineAnnouncementImpl(group=Group(703454734), senderId=1149159218, sender=NormalMember(1149159218), content=这是普通公告, parameters=AnnouncementParameters(image=null, sendToNewMember=false, isPinned=false, showEditCard=false, showPopup=false, requireConfirmation=false), fid=0edeed29000000001e10ee6380d50700, allConfirmed=false, confirmedMembersCount=0, publicationTime=1676546078)
2023-02-16 19:19:25.505 ERROR [DefaultDispatcher-worker-4] announcements-test.emit(22): e: kotlinx.serialization.MissingFieldException: Field 'msg' is required for type with serial name 'net.mamoe.mirai.internal.contact.announcement.GroupAnnouncement', but it was missing at path: $
群公告截图

image

测试的5条公告全部获取失败,看起来像是必然情况

换了一个258条公告的群测试,同样全部失败。

@Him188 Him188 added M 优先级: 主要 and removed N 优先级: 一般 z:wait-for-reply 状态: 等待回复 labels Feb 17, 2023
@cssxsh
Copy link
Contributor

cssxsh commented Feb 17, 2023

@Him188
Cooke 缺失
另外和
#2069
是一样的

都会报 {"ec":1,"em":"no login [errcode:1:0]","ltsm":1676628732,"srv_code":0}

原因是缺了 p_skey 或者 cookie 过期 或者 触发了 ktor 的 bug

@sandtechnology
Copy link
Collaborator

@Him188 Cooke 缺失 另外和 #2069 是一样的

都会报 {"ec":1,"em":"no login [errcode:1:0]","ltsm":1676628732,"srv_code":0}

原因是缺了 p_skey 或者 cookie 过期 或者 触发了 ktor 的 bug

这里看起来是结构有更新 并不是缺key看起来(

@cssxsh
Copy link
Contributor

cssxsh commented Feb 17, 2023

@Him188 Cooke 缺失 另外和 #2069 是一样的
都会报 {"ec":1,"em":"no login [errcode:1:0]","ltsm":1676628732,"srv_code":0}
原因是缺了 p_skey 或者 cookie 过期 或者 触发了 ktor 的 bug

这里看起来是结构有更新 并不是缺key看起来(

我刚测试,就是缺cookie了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants