fix: 修复 HarmonyOS BugCollect fingerprint 异步竞态问题
- Fingerprint.ets: computeFingerprint 改为同步函数 - BugCollect.ets: warn() 和 buildIssueEvent() 使用同步 fingerprint 计算 - 移除 .then() 异步调用,确保事件发送时 fingerprint 已计算完成 Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
父节点
65e7a3e2c3
当前提交
96246a4856
@ -111,7 +111,7 @@ export class BugCollect {
|
|||||||
eventId: BugCollect.generateUuid(),
|
eventId: BugCollect.generateUuid(),
|
||||||
level: 'warning',
|
level: 'warning',
|
||||||
platform: 'harmony',
|
platform: 'harmony',
|
||||||
fingerprint: '', // will be computed async
|
fingerprint: computeFingerprint('Warning', message, ''),
|
||||||
appKey: config.appKey,
|
appKey: config.appKey,
|
||||||
exception: { type: 'Warning', value: message },
|
exception: { type: 'Warning', value: message },
|
||||||
breadcrumbs: [...BugCollect.breadcrumbs],
|
breadcrumbs: [...BugCollect.breadcrumbs],
|
||||||
@ -124,11 +124,7 @@ export class BugCollect {
|
|||||||
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute fingerprint async
|
BugCollect.queue?.push(issue)
|
||||||
computeFingerprint('Warning', message, '').then(fp => {
|
|
||||||
issue.fingerprint = fp
|
|
||||||
BugCollect.queue?.push(issue)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,7 +191,7 @@ export class BugCollect {
|
|||||||
eventId: BugCollect.generateUuid(),
|
eventId: BugCollect.generateUuid(),
|
||||||
level,
|
level,
|
||||||
platform: 'harmony',
|
platform: 'harmony',
|
||||||
fingerprint: fingerprint ?? '', // will be computed async
|
fingerprint: fingerprint ?? computeFingerprint(error.name ?? 'Error', error.message ?? '', stacktrace),
|
||||||
appKey: config.appKey,
|
appKey: config.appKey,
|
||||||
exception: {
|
exception: {
|
||||||
type: error.name ?? 'Error',
|
type: error.name ?? 'Error',
|
||||||
@ -212,13 +208,6 @@ export class BugCollect {
|
|||||||
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
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
|
return event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
import cryptoFramework from '@ohos.security.cryptoFramework'
|
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 normalizedMessage = normalizeMessage(message)
|
||||||
const top3Frames = extractTop3Frames(stacktrace)
|
const top3Frames = extractTop3Frames(stacktrace)
|
||||||
const raw = `${type}:${normalizedMessage}:${top3Frames}`
|
const raw = `${type}:${normalizedMessage}:${top3Frames}`
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户