问题描述
含 markdown 段的群消息触发 dispatch error: Cannot read properties of undefined (reading 'length'),导致消息丢失不上报。
堆栈追踪
TypeError: Cannot read properties of undefined (reading 'length')
at new CodedReader (@saltify/typeproto/dist/index.mjs:23:24)
at ProtoMessage.decode (@saltify/typeproto/dist/index.mjs:927:18)
at parseElements (src/ntqqapi/helper/messageParsing.ts:20:39)
at convertToRawMessage (src/ntqqapi/dispatcher.ts:850:20)
at handleChatMessage (src/ntqqapi/dispatcher.ts:781:22)
at handleMsgPush (src/ntqqapi/dispatcher.ts:107:7)
根因
parseElements 函数中,elem.commonElem.pbElem 可能为 undefined,
直接传给 Msg.MarkdownExtra.decode(pbElem) 时,protobuf 库的 CodedReader
构造函数访问 undefined.length 导致崩溃。
复现条件
- LLOneBot 8.0.3
- NTQQ 桌面版
- 官方 bot 发送含 markdown 段的群消息
修复方案
1. parseElements 中 pbElem 空值检查
// src/ntqqapi/helper/messageParsing.ts
const pbElem = elem.commonElem.pbElem;
if (!pbElem) continue; // 添加此检查
2. TextResvAttr.decode 空值检查
if (isAt && textElem.attr6Buf.length >= 11 && textElem.attr6Buf[6] !== 1) {
if (!elem.text.pbReserve) continue; // 添加此检查
const attr = Msg.TextResvAttr.decode(elem.text.pbReserve);
}
3. parseMsgInfoElement 空值检查
function parseMsgInfoElement(pbElem, bizType) {
if (!pbElem) return null; // 添加此检查
const msgInfo = Media.MsgInfo.decode(pbElem);
}
问题描述
含 markdown 段的群消息触发
dispatch error: Cannot read properties of undefined (reading 'length'),导致消息丢失不上报。堆栈追踪
根因
parseElements函数中,elem.commonElem.pbElem可能为undefined,直接传给
Msg.MarkdownExtra.decode(pbElem)时,protobuf 库的 CodedReader构造函数访问
undefined.length导致崩溃。复现条件
修复方案
1.
parseElements中 pbElem 空值检查2. TextResvAttr.decode 空值检查
3. parseMsgInfoElement 空值检查