From 0cf9cdd0d7791b12061e9b0cc745ca9858d1ff88 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 30 Jun 2026 19:31:20 +0800 Subject: [PATCH] =?UTF-8?q?chore(core):=20diagnose=20ptt=20translate=20fai?= =?UTF-8?q?lures=20(#165=20=E5=A4=87=E9=80=89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When QQ's ASR returns a non-zero errCode, log the request fields we sourced from cache (md5 length / format / uuid presence / duration / size) alongside the errCode, so a server-side ASR failure can be told apart from our own missing/zero field. Behaviour unchanged — still throws. Helps diagnose the "ptt translate failed" instability reported in #165 before deciding whether it's our bug. --- packages/core/src/bridge/apis/extras.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/src/bridge/apis/extras.ts b/packages/core/src/bridge/apis/extras.ts index 64b0ade6..d142ac20 100644 --- a/packages/core/src/bridge/apis/extras.ts +++ b/packages/core/src/bridge/apis/extras.ts @@ -7,6 +7,7 @@ import { GetStrangerStatus, type StrangerStatus as NamespaceStrangerStatus } fro import { GroupTodo } from '@snowluma/protocol/oidb-services/extras/group-todo'; import { convertAudioBytes } from '@snowluma/protocol/highway/ffmpeg-addon'; import { loadBinarySource } from '@snowluma/protocol/highway/utils'; +import { createLogger } from '@snowluma/common/logger'; import type { PttTransReq, PttTransResp } from '@snowluma/proto-defs/ptt-trans'; import { protobuf_decode, protobuf_encode } from '@snowluma/proton'; import type { BridgeContext } from '../bridge-context'; @@ -57,6 +58,8 @@ export interface AiVoiceItem { voiceExampleUrl: string; } +const log = createLogger('Bridge.Extras'); + export class ExtrasApi { constructor(private readonly ctx: BridgeContext) { } @@ -156,7 +159,18 @@ export class ExtrasApi { } const resp = protobuf_decode(result.responseData); const item = input.isGroup ? resp?.groupResult : resp?.c2cResult; - if (item?.errCode) throw new Error(`ptt translate failed: error=${item.errCode}`); + if (item?.errCode) { + // Diagnostic (#165 备选): correlate QQ's errCode with the request fields we + // sourced from cache, to tell a server-side ASR failure apart from our own + // missing/zero field (md5/format/uuid). Behaviour unchanged — still throws. + log.warn( + 'ptt translate errCode=%d isGroup=%s md5=%s format=%d uuid=%s dur=%d size=%d', + item.errCode, input.isGroup, + input.md5Hex ? `${input.md5Hex.length / 2}B` : 'EMPTY', + input.format, input.uuid ? 'set' : 'EMPTY', input.duration, input.size, + ); + throw new Error(`ptt translate failed: error=${item.errCode}`); + } return item?.text ?? ''; // '' = transcribing async; caller awaits the push }