mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(exception): optimize exception report behavior
This commit is contained in:
@@ -3,7 +3,9 @@ package work.slhaf.partner.framework.agent.config
|
||||
import com.alibaba.fastjson2.JSON
|
||||
import com.alibaba.fastjson2.JSONObject
|
||||
import org.slf4j.LoggerFactory
|
||||
import work.slhaf.partner.framework.agent.exception.AgentRuntimeException
|
||||
import work.slhaf.partner.framework.agent.exception.AgentStartupException
|
||||
import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler
|
||||
import work.slhaf.partner.framework.agent.exception.checkAgentStartup
|
||||
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport
|
||||
import java.io.IOException
|
||||
@@ -197,7 +199,7 @@ object ConfigCenter : AutoCloseable {
|
||||
(registration as ConfigRegistration<Config>).onReload(pair.first, pair.second)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Config reload failed: {}", relativePath, e)
|
||||
ExceptionReporterHandler.report(AgentRuntimeException("Config load failed: $relativePath", e))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +208,7 @@ object ConfigCenter : AutoCloseable {
|
||||
val json = JSON.parseObject(Files.readString(file, StandardCharsets.UTF_8))
|
||||
val config = json.toJavaObject(registration.type())
|
||||
config to json
|
||||
} catch (e: Exception) {
|
||||
log.error("Config reload failed: {}", file, e)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ abstract class AgentException @JvmOverloads constructor(
|
||||
return ExceptionReport(
|
||||
this::class.java.simpleName,
|
||||
message ?: "",
|
||||
cause
|
||||
this
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,12 @@ abstract class AgentException @JvmOverloads constructor(
|
||||
data class ExceptionReport @JvmOverloads constructor(
|
||||
val type: String,
|
||||
val message: String,
|
||||
val cause: Throwable? = null,
|
||||
val exception: Throwable? = null,
|
||||
val extra: MutableMap<String, Any?> = linkedMapOf()
|
||||
) {
|
||||
|
||||
override fun toString(): String {
|
||||
val cause = exception?.cause
|
||||
val causeType = cause?.javaClass?.simpleName ?: ""
|
||||
val causeMessage = cause?.message ?: ""
|
||||
return """type: $type,
|
||||
@@ -36,8 +37,8 @@ data class ExceptionReport @JvmOverloads constructor(
|
||||
|
||||
fun toDetailedString(): String {
|
||||
return buildString {
|
||||
appendLine(toString())
|
||||
val stackTrace = cause?.stackTraceToString()
|
||||
appendLine(this@ExceptionReport.toString())
|
||||
val stackTrace = exception?.stackTraceToString()
|
||||
if (!stackTrace.isNullOrBlank()) {
|
||||
appendLine("stackTrace:")
|
||||
appendLine(stackTrace)
|
||||
|
||||
Reference in New Issue
Block a user