fix: BugCollect.captureError 在 SDK 未初始化时不再崩溃
- captureError 检查 XuqmSDK.isInitialized() 再访问 appKey - SDK 未初始化时将错误加入待处理队列,初始化后自动 flush - captureCrash 也添加 isInitialized 检查 Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
父节点
79463a5808
当前提交
04eb0d13d3
@ -62,6 +62,34 @@ object BugCollect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun captureError(error: Throwable, tags: Map<String, Any?> = emptyMap(), fingerprint: String? = null) {
|
fun captureError(error: Throwable, tags: Map<String, Any?> = emptyMap(), fingerprint: String? = null) {
|
||||||
|
// SDK 未初始化时,将错误加入待处理队列
|
||||||
|
if (!XuqmSDK.isInitialized()) {
|
||||||
|
val event = IssueEvent(
|
||||||
|
level = "error",
|
||||||
|
platform = "android",
|
||||||
|
fingerprint = fingerprint ?: Fingerprint.compute(
|
||||||
|
error.javaClass.simpleName,
|
||||||
|
error.message ?: error.javaClass.name,
|
||||||
|
error.stackTraceToString(),
|
||||||
|
),
|
||||||
|
appKey = "pending",
|
||||||
|
exception = IssueEvent.ExceptionInfo(
|
||||||
|
type = error.javaClass.simpleName,
|
||||||
|
value = error.message ?: error.javaClass.name,
|
||||||
|
stacktrace = error.stackTraceToString(),
|
||||||
|
),
|
||||||
|
breadcrumbs = emptyList(),
|
||||||
|
release = appVersion(),
|
||||||
|
environment = environment,
|
||||||
|
userId = "unknown",
|
||||||
|
user = IssueEvent.UserInfo(id = "unknown"),
|
||||||
|
device = buildDeviceInfo(),
|
||||||
|
tags = tags,
|
||||||
|
)
|
||||||
|
synchronized(pendingErrorsLock) { pendingErrors.add(event) }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val crumbs = synchronized(breadcrumbLock) { breadcrumbBuffer.toList() }
|
val crumbs = synchronized(breadcrumbLock) { breadcrumbBuffer.toList() }
|
||||||
val fp = fingerprint ?: Fingerprint.compute(
|
val fp = fingerprint ?: Fingerprint.compute(
|
||||||
error.javaClass.simpleName,
|
error.javaClass.simpleName,
|
||||||
@ -95,7 +123,8 @@ object BugCollect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun captureCrash(error: Throwable, tags: Map<String, Any?> = emptyMap()) {
|
fun captureCrash(error: Throwable, tags: Map<String, Any?> = emptyMap()) {
|
||||||
if (!isReady()) return
|
// SDK 未初始化时直接返回,崩溃事件无法缓存
|
||||||
|
if (!XuqmSDK.isInitialized() || !isReady()) return
|
||||||
val crumbs = synchronized(breadcrumbLock) { breadcrumbBuffer.toList() }
|
val crumbs = synchronized(breadcrumbLock) { breadcrumbBuffer.toList() }
|
||||||
queue().push(IssueEvent(
|
queue().push(IssueEvent(
|
||||||
level = "fatal",
|
level = "fatal",
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户