mirror of
https://github.com/corda/corda.git
synced 2025-06-01 15:10:54 +00:00
Merging forward updates from release/os/4.12 to release/os/4.13 - 2025-03-05
This commit is contained in:
commit
3a2b3ae5a7
@ -1,7 +1,5 @@
|
|||||||
package net.corda.common.logging
|
package net.corda.common.logging
|
||||||
|
|
||||||
import org.apache.logging.log4j.Level
|
|
||||||
import org.apache.logging.log4j.message.Message
|
|
||||||
import org.apache.logging.log4j.message.SimpleMessage
|
import org.apache.logging.log4j.message.SimpleMessage
|
||||||
import java.util.*
|
import java.util.*
|
||||||
//Returns an iterator that traverses all the exception's cause chain stopping in case of loops (an exception caused by itself)
|
//Returns an iterator that traverses all the exception's cause chain stopping in case of loops (an exception caused by itself)
|
||||||
@ -28,18 +26,6 @@ fun Throwable.walkExceptionCausedByList() : Iterator<Throwable> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Message.withErrorCodeFor(error: Throwable?, level: Level): Message {
|
|
||||||
|
|
||||||
return when {
|
|
||||||
error != null && level.isInRange(Level.FATAL, Level.WARN) -> {
|
|
||||||
val logMessage = this.formattedMessage
|
|
||||||
val message = error.walkExceptionCausedByList().asSequence().mapNotNull(Throwable::message).joinToString(" - ")
|
|
||||||
CompositeMessage("$logMessage - $message [errorCode=${error.errorCode()}, moreInformationAt=${error.errorCodeLocationUrl()}]", format, parameters, throwable)
|
|
||||||
}
|
|
||||||
else -> this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Throwable.errorCodeLocationUrl() = "https://errors.corda.net/${CordaVersion.platformEditionCode}/${CordaVersion.semanticVersion}/${errorCode()}"
|
fun Throwable.errorCodeLocationUrl() = "https://errors.corda.net/${CordaVersion.platformEditionCode}/${CordaVersion.semanticVersion}/${errorCode()}"
|
||||||
|
|
||||||
fun Throwable.errorCode(hashedFields: (Throwable) -> Array<out Any?> = Throwable::defaultHashedFields): String {
|
fun Throwable.errorCode(hashedFields: (Throwable) -> Array<out Any?> = Throwable::defaultHashedFields): String {
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package net.corda.commmon.logging
|
|
||||||
|
|
||||||
import com.natpryce.hamkrest.assertion.assertThat
|
|
||||||
import com.natpryce.hamkrest.contains
|
|
||||||
import net.corda.common.logging.withErrorCodeFor
|
|
||||||
import org.apache.logging.log4j.Level
|
|
||||||
import org.apache.logging.log4j.message.SimpleMessage
|
|
||||||
import org.junit.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class ExceptionsErrorCodeFunctionsTest {
|
|
||||||
private companion object {
|
|
||||||
private const val EXCEPTION_MESSAGE = "This is exception "
|
|
||||||
private const val TEST_MESSAGE = "This is a test message"
|
|
||||||
private fun makeChain(previous: Exception?, ttl: Int): Exception {
|
|
||||||
val current = TestThrowable(ttl, previous)
|
|
||||||
return if (ttl == 0) {
|
|
||||||
current
|
|
||||||
} else {
|
|
||||||
makeChain(current, ttl - 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(timeout=5_000)
|
|
||||||
fun `error code for message prints out message and full stack trace`() {
|
|
||||||
val originalMessage = SimpleMessage(TEST_MESSAGE)
|
|
||||||
val exception = makeChain(null, 10)
|
|
||||||
val message = originalMessage.withErrorCodeFor(exception, Level.ERROR)
|
|
||||||
assertThat(message.formattedMessage, contains(TEST_MESSAGE.toRegex()))
|
|
||||||
for (i in (0..10)) {
|
|
||||||
assertThat(message.formattedMessage, contains("$EXCEPTION_MESSAGE $i".toRegex()))
|
|
||||||
}
|
|
||||||
assertEquals(message.format, originalMessage.format)
|
|
||||||
assertEquals(message.parameters, originalMessage.parameters)
|
|
||||||
assertEquals(message.throwable, originalMessage.throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestThrowable(index: Int, cause: Exception?) : Exception("$EXCEPTION_MESSAGE $index", cause)
|
|
||||||
}
|
|
@ -51,7 +51,7 @@ jerseyVersion=3.1.6
|
|||||||
servletVersion=4.0.1
|
servletVersion=4.0.1
|
||||||
assertjVersion=3.12.2
|
assertjVersion=3.12.2
|
||||||
slf4JVersion=2.0.12
|
slf4JVersion=2.0.12
|
||||||
log4JVersion=2.23.0
|
log4JVersion=2.24.3
|
||||||
okhttpVersion=4.12.0
|
okhttpVersion=4.12.0
|
||||||
nettyVersion=4.1.115.Final
|
nettyVersion=4.1.115.Final
|
||||||
fileuploadVersion=2.0.0-M1
|
fileuploadVersion=2.0.0-M1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user