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.JSON
|
||||||
import com.alibaba.fastjson2.JSONObject
|
import com.alibaba.fastjson2.JSONObject
|
||||||
import org.slf4j.LoggerFactory
|
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.AgentStartupException
|
||||||
|
import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler
|
||||||
import work.slhaf.partner.framework.agent.exception.checkAgentStartup
|
import work.slhaf.partner.framework.agent.exception.checkAgentStartup
|
||||||
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport
|
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -197,7 +199,7 @@ object ConfigCenter : AutoCloseable {
|
|||||||
(registration as ConfigRegistration<Config>).onReload(pair.first, pair.second)
|
(registration as ConfigRegistration<Config>).onReload(pair.first, pair.second)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} 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 json = JSON.parseObject(Files.readString(file, StandardCharsets.UTF_8))
|
||||||
val config = json.toJavaObject(registration.type())
|
val config = json.toJavaObject(registration.type())
|
||||||
config to json
|
config to json
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
log.error("Config reload failed: {}", file, e)
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ abstract class AgentException @JvmOverloads constructor(
|
|||||||
return ExceptionReport(
|
return ExceptionReport(
|
||||||
this::class.java.simpleName,
|
this::class.java.simpleName,
|
||||||
message ?: "",
|
message ?: "",
|
||||||
cause
|
this
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,11 +19,12 @@ abstract class AgentException @JvmOverloads constructor(
|
|||||||
data class ExceptionReport @JvmOverloads constructor(
|
data class ExceptionReport @JvmOverloads constructor(
|
||||||
val type: String,
|
val type: String,
|
||||||
val message: String,
|
val message: String,
|
||||||
val cause: Throwable? = null,
|
val exception: Throwable? = null,
|
||||||
val extra: MutableMap<String, Any?> = linkedMapOf()
|
val extra: MutableMap<String, Any?> = linkedMapOf()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
val cause = exception?.cause
|
||||||
val causeType = cause?.javaClass?.simpleName ?: ""
|
val causeType = cause?.javaClass?.simpleName ?: ""
|
||||||
val causeMessage = cause?.message ?: ""
|
val causeMessage = cause?.message ?: ""
|
||||||
return """type: $type,
|
return """type: $type,
|
||||||
@@ -36,8 +37,8 @@ data class ExceptionReport @JvmOverloads constructor(
|
|||||||
|
|
||||||
fun toDetailedString(): String {
|
fun toDetailedString(): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
appendLine(toString())
|
appendLine(this@ExceptionReport.toString())
|
||||||
val stackTrace = cause?.stackTraceToString()
|
val stackTrace = exception?.stackTraceToString()
|
||||||
if (!stackTrace.isNullOrBlank()) {
|
if (!stackTrace.isNullOrBlank()) {
|
||||||
appendLine("stackTrace:")
|
appendLine("stackTrace:")
|
||||||
appendLine(stackTrace)
|
appendLine(stackTrace)
|
||||||
|
|||||||
Reference in New Issue
Block a user