fix: 修复 HarmonyOS BugCollect fingerprint 异步竞态问题

- Fingerprint.ets: computeFingerprint 改为同步函数
- BugCollect.ets: warn() 和 buildIssueEvent() 使用同步 fingerprint 计算
- 移除 .then() 异步调用,确保事件发送时 fingerprint 已计算完成

Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-06-19 15:48:06 +08:00
父节点 65e7a3e2c3
当前提交 96246a4856
共有 2 个文件被更改,包括 5 次插入16 次删除

查看文件

@ -111,7 +111,7 @@ export class BugCollect {
eventId: BugCollect.generateUuid(),
level: 'warning',
platform: 'harmony',
fingerprint: '', // will be computed async
fingerprint: computeFingerprint('Warning', message, ''),
appKey: config.appKey,
exception: { type: 'Warning', value: message },
breadcrumbs: [...BugCollect.breadcrumbs],
@ -124,11 +124,7 @@ export class BugCollect {
sdk: { name: SDK_NAME, version: SDK_VERSION },
}
// Compute fingerprint async
computeFingerprint('Warning', message, '').then(fp => {
issue.fingerprint = fp
BugCollect.queue?.push(issue)
})
BugCollect.queue?.push(issue)
}
/**
@ -195,7 +191,7 @@ export class BugCollect {
eventId: BugCollect.generateUuid(),
level,
platform: 'harmony',
fingerprint: fingerprint ?? '', // will be computed async
fingerprint: fingerprint ?? computeFingerprint(error.name ?? 'Error', error.message ?? '', stacktrace),
appKey: config.appKey,
exception: {
type: error.name ?? 'Error',
@ -212,13 +208,6 @@ export class BugCollect {
sdk: { name: SDK_NAME, version: SDK_VERSION },
}
// Compute fingerprint async
if (!fingerprint) {
computeFingerprint(error.name ?? 'Error', error.message ?? '', stacktrace).then(fp => {
event.fingerprint = fp
})
}
return event
}

查看文件

@ -5,9 +5,9 @@
import cryptoFramework from '@ohos.security.cryptoFramework'
/**
* 计算错误指纹
* 计算错误指纹(同步版本)
*/
export async function computeFingerprint(type: string, message: string, stacktrace?: string): Promise<string> {
export function computeFingerprint(type: string, message: string, stacktrace?: string): string {
const normalizedMessage = normalizeMessage(message)
const top3Frames = extractTop3Frames(stacktrace)
const raw = `${type}:${normalizedMessage}:${top3Frames}`