如何获得修复此错误的 Stacktrace?
How can I get the Stacktrace of this error of fix it?
嘿,我尝试在 Kotlin Hands 上使用 Ktor。但我在使用“/”访问网页时遇到问题。
embeddedServer(Netty, port) {
install(FreeMarker) {
templateLoader = ClassTemplateLoader(this::class.java.classLoader, "templates")
outputFormat = HTMLOutputFormat.INSTANCE
}
routing {
static("/static") {
resources("files")
}
get("/") {
call.respond(FreeMarkerContent("index.ftl", mapOf("entries" to blogEntries), ""))
}
}
}.start(wait = false)
这是我使用的代码。我找不到错误,控制台中只有这条消息:
[eventLoopGroupProxy-4-1] INFO ktor.application - Unhandled: GET - /, io failed
有没有人知道我该如何解决这个错误?
我建议使用 CallLogging feature and routes tracing 来解决您的问题。
生成该消息的确切行在 io.ktor.server.engine.logFailure
中:https://github.com/ktorio/ktor/blob/2e1b0046e4235865da7cbbfbf2e887f410775278/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/DefaultEnginePipeline.kt#L107
private fun ApplicationEnvironment.logFailure(call: ApplicationCall, cause: Throwable) {
...
is IOException -> log.info("$status: $logString, io failed: ${cause.message ?: "unknown error"}")
...
}
在此行添加一个断点。然后,当您的应用程序失败时,cause
将包含真正的异常。
在我的例子中,这是 FreeMarker 模板中的一个错误。这很奇怪,因为通常这些异常会正常打印。这次它只打印了 Unhandled: <route>, io failed
.
这似乎是 Ktor 中的一个错误:这些异常是在正常行为中抛出的,而且非常频繁,以至于您不需要完整的堆栈跟踪。但有时(如本例)异常不正常,您确实需要堆栈跟踪。
嘿,我尝试在 Kotlin Hands 上使用 Ktor。但我在使用“/”访问网页时遇到问题。
embeddedServer(Netty, port) {
install(FreeMarker) {
templateLoader = ClassTemplateLoader(this::class.java.classLoader, "templates")
outputFormat = HTMLOutputFormat.INSTANCE
}
routing {
static("/static") {
resources("files")
}
get("/") {
call.respond(FreeMarkerContent("index.ftl", mapOf("entries" to blogEntries), ""))
}
}
}.start(wait = false)
这是我使用的代码。我找不到错误,控制台中只有这条消息:
[eventLoopGroupProxy-4-1] INFO ktor.application - Unhandled: GET - /, io failed
有没有人知道我该如何解决这个错误?
我建议使用 CallLogging feature and routes tracing 来解决您的问题。
生成该消息的确切行在 io.ktor.server.engine.logFailure
中:https://github.com/ktorio/ktor/blob/2e1b0046e4235865da7cbbfbf2e887f410775278/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/DefaultEnginePipeline.kt#L107
private fun ApplicationEnvironment.logFailure(call: ApplicationCall, cause: Throwable) {
...
is IOException -> log.info("$status: $logString, io failed: ${cause.message ?: "unknown error"}")
...
}
在此行添加一个断点。然后,当您的应用程序失败时,cause
将包含真正的异常。
在我的例子中,这是 FreeMarker 模板中的一个错误。这很奇怪,因为通常这些异常会正常打印。这次它只打印了 Unhandled: <route>, io failed
.
这似乎是 Ktor 中的一个错误:这些异常是在正常行为中抛出的,而且非常频繁,以至于您不需要完整的堆栈跟踪。但有时(如本例)异常不正常,您确实需要堆栈跟踪。