chore(msg-push): log body of empty-decoded messages (#102 diagnostic)
A group invite surfaces a content-less "[空消息]" friend message (#102). Before deciding whether to drop or decode it, we need to know what its body actually carries — SnowLuma's decoder covers fewer element types than Lagrange, so an empty decode may be a missing decoder (real content) rather than a genuinely empty control push. parseMsgPush now warns, on any message that decodes to zero elements, with a summary of the body: each element's field names, every commonElem's serviceType/businessType + payload hex, and any msgContent. One log line is enough to identify the culprit element offline. No behavior change — the message still dispatches as before. Temporary; remove once the #102 culprit is identified and handled.
This commit is contained in:
1 file changed
+51
-2
@@ -1,7 +1,10 @@
|
|||||||
|
import { hexPreview } from '@snowluma/common/hex';
|
||||||
|
import { createLogger } from '@snowluma/common/logger';
|
||||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||||
|
import type { Elem } from '@snowluma/proto-defs/element';
|
||||||
import type { QQEventVariant } from '../events';
|
import type { QQEventVariant } from '../events';
|
||||||
import type { IdentityService } from '../identity-service';
|
import type { IdentityService } from '../identity-service';
|
||||||
import { buildContext } from './context';
|
import { buildContext, type PushMsgBody } from './context';
|
||||||
import { decodeEvent0x210 } from './decoders/event-0x210';
|
import { decodeEvent0x210 } from './decoders/event-0x210';
|
||||||
import { decodeEvent0x2DC } from './decoders/event-0x2dc';
|
import { decodeEvent0x2DC } from './decoders/event-0x2dc';
|
||||||
import { decodeFriendMessage } from './decoders/friend-message';
|
import { decodeFriendMessage } from './decoders/friend-message';
|
||||||
@@ -42,8 +45,54 @@ registry.register([
|
|||||||
PkgType.PrivateFileMessage,
|
PkgType.PrivateFileMessage,
|
||||||
], decodeFriendMessage);
|
], decodeFriendMessage);
|
||||||
|
|
||||||
|
const log = createLogger('MsgPush');
|
||||||
|
|
||||||
|
// Kinds that carry decoded `elements`; an empty list surfaces to clients as the
|
||||||
|
// confusing "[空消息]".
|
||||||
|
const MESSAGE_KINDS = new Set<QQEventVariant['kind']>([
|
||||||
|
'friend_message', 'group_message', 'temp_message',
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnostic for issue #102 (group invite → "[空消息]"). When a message decodes
|
||||||
|
* to zero elements, dump what its body actually carried — each element's field
|
||||||
|
* names, every `commonElem`'s serviceType/businessType + payload hex, and any
|
||||||
|
* `msgContent` — so we can tell a genuinely content-less control push from an
|
||||||
|
* element type we simply don't decode yet (and then decode it, rather than
|
||||||
|
* blindly dropping the message). TODO(#102): remove once the culprit element is
|
||||||
|
* identified and handled.
|
||||||
|
*/
|
||||||
|
function describeUndecodedBody(body: PushMsgBody | undefined): string {
|
||||||
|
const elems = (body?.richText?.elems ?? []) as Elem[];
|
||||||
|
const parts = elems.map((e) => {
|
||||||
|
if (e.commonElem) {
|
||||||
|
const ce = e.commonElem;
|
||||||
|
const pb = ce.pbElem && ce.pbElem.length > 0 ? ` pbElem=${hexPreview(ce.pbElem, 256)}` : '';
|
||||||
|
return `commonElem(svc=${ce.serviceType ?? 0},biz=${ce.businessType ?? 0})${pb}`;
|
||||||
|
}
|
||||||
|
const keys = Object.keys(e).filter((k) => (e as Record<string, unknown>)[k] != null);
|
||||||
|
return keys.join('+') || '(empty)';
|
||||||
|
});
|
||||||
|
const extras: string[] = [];
|
||||||
|
if (body?.richText?.ptt) extras.push('ptt');
|
||||||
|
if (body?.richText?.notOnlineFile) extras.push('notOnlineFile');
|
||||||
|
if (body?.msgContent && body.msgContent.length > 0) {
|
||||||
|
extras.push(`msgContent=${hexPreview(body.msgContent, 256)}`);
|
||||||
|
}
|
||||||
|
return `elems=[${parts.join('; ')}]${extras.length ? ` ${extras.join(' ')}` : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseMsgPush(pkt: PacketInfo, identity: IdentityService): QQEventVariant[] {
|
export function parseMsgPush(pkt: PacketInfo, identity: IdentityService): QQEventVariant[] {
|
||||||
const ctx = buildContext(pkt, identity);
|
const ctx = buildContext(pkt, identity);
|
||||||
if (!ctx) return [];
|
if (!ctx) return [];
|
||||||
return registry.decode(ctx);
|
const events = registry.decode(ctx);
|
||||||
|
// #102 diagnostic — surface what an empty-decoded message actually contained.
|
||||||
|
for (const ev of events) {
|
||||||
|
if (MESSAGE_KINDS.has(ev.kind) && (ev as { elements?: unknown[] }).elements?.length === 0) {
|
||||||
|
log.warn('[#102] empty message (kind=%s seq=%d from=%d msgType=%d/%d): %s',
|
||||||
|
ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.subType,
|
||||||
|
describeUndecodedBody(ctx.body));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return events;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user