mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
[CORDA-1996]: Apply error code to exceptions that do not propagate to NodeStartup. (#3964)
This commit is contained in:
committed by
GitHub
parent
4fd8a8fb29
commit
19b8f70117
@ -8,7 +8,6 @@ import net.corda.core.flows.InitiatingFlow
|
||||
import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.internal.concurrent.map
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
@ -28,7 +27,6 @@ import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import rx.Observable
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
|
@ -1,39 +0,0 @@
|
||||
package net.corda.node.internal
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun Exception.errorCode(hashedFields: (Throwable) -> Array<out Any?> = Throwable::defaultHashedFields): String {
|
||||
val hash = staticLocationBasedHash(hashedFields)
|
||||
return hash.toBase(36)
|
||||
}
|
||||
|
||||
private fun Throwable.staticLocationBasedHash(hashedFields: (Throwable) -> Array<out Any?>, visited: Set<Throwable> = setOf(this)): Int {
|
||||
val cause = this.cause
|
||||
val fields = hashedFields.invoke(this)
|
||||
return when {
|
||||
cause != null && !visited.contains(cause) -> Objects.hash(*fields, cause.staticLocationBasedHash(hashedFields, visited + cause))
|
||||
else -> Objects.hash(*fields)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.toBase(base: Int): String = Integer.toUnsignedString(this, base)
|
||||
|
||||
private fun Array<StackTraceElement?>.customHashCode(maxElementsToConsider: Int = this.size): Int {
|
||||
|
||||
return Arrays.hashCode(take(maxElementsToConsider).map { it?.customHashCode() ?: 0 }.toIntArray())
|
||||
}
|
||||
|
||||
private fun StackTraceElement.customHashCode(hashedFields: (StackTraceElement) -> Array<out Any?> = StackTraceElement::defaultHashedFields): Int {
|
||||
|
||||
return Objects.hash(*hashedFields.invoke(this))
|
||||
}
|
||||
|
||||
private fun Throwable.defaultHashedFields(): Array<out Any?> {
|
||||
|
||||
return arrayOf(this::class.java.name, stackTrace?.customHashCode(3) ?: 0)
|
||||
}
|
||||
|
||||
private fun StackTraceElement.defaultHashedFields(): Array<out Any?> {
|
||||
|
||||
return arrayOf(className, methodName)
|
||||
}
|
@ -154,9 +154,9 @@ open class NodeStartup : CordaCliWrapper("corda", "Runs a Corda Node") {
|
||||
|
||||
private val startNodeExpectedErrors = setOf(MultipleCordappsForFlowException::class, CheckpointIncompatibleException::class, AddressBindingException::class, NetworkParametersReader::class, DatabaseIncompatibleException::class)
|
||||
|
||||
private fun Exception.logAsExpected(message: String? = this.message, print: (String?) -> Unit = logger::error) = print("$message [errorCode=${errorCode()}]")
|
||||
private fun Exception.logAsExpected(message: String? = this.message, print: (String?) -> Unit = logger::error) = print(message)
|
||||
|
||||
private fun Exception.logAsUnexpected(message: String? = this.message, error: Exception = this, print: (String?, Throwable) -> Unit = logger::error) = print("$message${this.message?.let { ": $it" } ?: ""} [errorCode=${errorCode()}]", error)
|
||||
private fun Exception.logAsUnexpected(message: String? = this.message, error: Exception = this, print: (String?, Throwable) -> Unit = logger::error) = print("$message${this.message?.let { ": $it" } ?: ""}", error)
|
||||
|
||||
private fun Exception.isOpenJdkKnownIssue() = message?.startsWith("Unknown named curve:") == true
|
||||
|
||||
|
Reference in New Issue
Block a user