From 1016472e2ec2c738821d0eecec5f423861a598eb Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 20 Jun 2026 13:48:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=AE=9A=E7=A7=BB=E5=8A=A8=E5=A3=B3?= =?UTF-8?q?=E6=9C=AA=E7=9F=A5=E5=BC=82=E5=B8=B8=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移动端 HostBridge 未知异常统一返回稳定 host_error 文案 移动壳协议测试覆盖普通 Error 不透出原生消息 移动壳配置检查反查未知异常不可透出 Error.message --- apps/mobile-shell/scripts/check-config.mjs | 7 +++++++ apps/mobile-shell/src/host-bridge/protocol.test.ts | 2 +- apps/mobile-shell/src/host-bridge/protocol.ts | 5 +---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/mobile-shell/scripts/check-config.mjs b/apps/mobile-shell/scripts/check-config.mjs index 7a4d49b0b..1210a3472 100644 --- a/apps/mobile-shell/scripts/check-config.mjs +++ b/apps/mobile-shell/scripts/check-config.mjs @@ -914,6 +914,13 @@ for (const expectedErrorCode of [ ); } } +if ( + protocolSource.includes('error instanceof Error') || + protocolSource.includes('? error.message') || + protocolSource.includes('error.message\n :') +) { + throw new Error('mobile shell protocol must not expose unknown native Error.message values to H5'); +} for (const snippet of [ 'parseRequest', 'isHostBridgeRequest', diff --git a/apps/mobile-shell/src/host-bridge/protocol.test.ts b/apps/mobile-shell/src/host-bridge/protocol.test.ts index c2cd0df97..68feed41c 100644 --- a/apps/mobile-shell/src/host-bridge/protocol.test.ts +++ b/apps/mobile-shell/src/host-bridge/protocol.test.ts @@ -106,7 +106,7 @@ describe('mobile HostBridge protocol helpers', () => { }); expect(normalizeMobileHostBridgeError(new Error('disk failed'))).toEqual({ code: 'host_error', - message: 'disk failed', + message: 'mobile host bridge request failed', }); expect(normalizeMobileHostBridgeError('boom')).toEqual({ code: 'host_error', diff --git a/apps/mobile-shell/src/host-bridge/protocol.ts b/apps/mobile-shell/src/host-bridge/protocol.ts index 0fb2938e7..d5b8b2a58 100644 --- a/apps/mobile-shell/src/host-bridge/protocol.ts +++ b/apps/mobile-shell/src/host-bridge/protocol.ts @@ -107,9 +107,6 @@ export function normalizeMobileHostBridgeError(error: unknown): HostBridgeError return { code: 'host_error', - message: - error instanceof Error - ? error.message - : 'mobile host bridge request failed', + message: 'mobile host bridge request failed', }; }