diff --git a/node/src/integration-test/kotlin/net/corda/node/logging/ErrorCodeLoggingTests.kt b/node/src/integration-test/kotlin/net/corda/node/logging/ErrorCodeLoggingTests.kt index 3b07bcbb49..a22ab7a8dc 100644 --- a/node/src/integration-test/kotlin/net/corda/node/logging/ErrorCodeLoggingTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/logging/ErrorCodeLoggingTests.kt @@ -22,7 +22,7 @@ class ErrorCodeLoggingTests { node.rpc.startFlow(::MyFlow).waitForCompletion() val logFile = node.logFile() - val linesWithErrorCode = logFile.useLines { lines -> lines.filter { line -> line.contains("[errorCode=") }.toList() } + val linesWithErrorCode = logFile.useLines { lines -> lines.filter { line -> line.contains("[errorCode=") }.filter { line -> line.contains("moreInformationAt=https://errors.corda.net/") }.toList() } assertThat(linesWithErrorCode).isNotEmpty } diff --git a/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaVersionProvider.kt b/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaVersionProvider.kt index 85f9e9100b..0231f9d1d5 100644 --- a/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaVersionProvider.kt +++ b/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaVersionProvider.kt @@ -9,12 +9,18 @@ import picocli.CommandLine */ class CordaVersionProvider : CommandLine.IVersionProvider { companion object { + private const val UNKNOWN = "Unknown" + const val current_major_release = "4.0-SNAPSHOT" + const val platformEditionCode = "OS" + private fun manifestValue(name: String): String? = if (Manifests.exists(name)) Manifests.read(name) else null - val releaseVersion: String by lazy { manifestValue("Corda-Release-Version") ?: "Unknown" } - val revision: String by lazy { manifestValue("Corda-Revision") ?: "Unknown" } - val vendor: String by lazy { manifestValue("Corda-Vendor") ?: "Unknown" } + val releaseVersion: String by lazy { manifestValue("Corda-Release-Version") ?: UNKNOWN } + val revision: String by lazy { manifestValue("Corda-Revision") ?: UNKNOWN } + val vendor: String by lazy { manifestValue("Corda-Vendor") ?: UNKNOWN } val platformVersion: Int by lazy { manifestValue("Corda-Platform-Version")?.toInt() ?: 1 } + + internal val semanticVersion: String by lazy { if(releaseVersion == UNKNOWN) current_major_release else releaseVersion } } override fun getVersion(): Array { diff --git a/tools/cliutils/src/main/kotlin/net/corda/cliutils/ErrorCodeRewritePolicy.kt b/tools/cliutils/src/main/kotlin/net/corda/cliutils/ErrorCodeRewritePolicy.kt index dc35739ea7..dd0d587339 100644 --- a/tools/cliutils/src/main/kotlin/net/corda/cliutils/ErrorCodeRewritePolicy.kt +++ b/tools/cliutils/src/main/kotlin/net/corda/cliutils/ErrorCodeRewritePolicy.kt @@ -9,9 +9,9 @@ import org.apache.logging.log4j.core.impl.Log4jLogEvent @Plugin(name = "ErrorCodeRewritePolicy", category = Core.CATEGORY_NAME, elementType = "rewritePolicy", printObject = false) class ErrorCodeRewritePolicy : RewritePolicy { - override fun rewrite(source: LogEvent?): LogEvent? { - val newMessage = source?.message?.withErrorCodeFor(source.thrown, source.level) - return if (newMessage == source?.message) { + override fun rewrite(source: LogEvent): LogEvent? { + val newMessage = source.message?.withErrorCodeFor(source.thrown, source.level) + return if (newMessage == source.message) { source } else { Log4jLogEvent.Builder(source).setMessage(newMessage).build() diff --git a/tools/cliutils/src/main/kotlin/net/corda/cliutils/ExceptionsErrorCodeFunctions.kt b/tools/cliutils/src/main/kotlin/net/corda/cliutils/ExceptionsErrorCodeFunctions.kt index 08dbfcd157..ec7d74fb0a 100644 --- a/tools/cliutils/src/main/kotlin/net/corda/cliutils/ExceptionsErrorCodeFunctions.kt +++ b/tools/cliutils/src/main/kotlin/net/corda/cliutils/ExceptionsErrorCodeFunctions.kt @@ -8,11 +8,13 @@ import java.util.* internal fun Message.withErrorCodeFor(error: Throwable?, level: Level): Message { return when { - error != null && level.isInRange(Level.FATAL, Level.WARN) -> CompositeMessage("$formattedMessage [errorCode=${error.errorCode()}]", format, parameters, throwable) + error != null && level.isInRange(Level.FATAL, Level.WARN) -> CompositeMessage("$formattedMessage [errorCode=${error.errorCode()}, moreInformationAt=${error.errorCodeLocationUrl()}]", format, parameters, throwable) else -> this } } +private fun Throwable.errorCodeLocationUrl() = "https://errors.corda.net/${CordaVersionProvider.platformEditionCode}/${CordaVersionProvider.semanticVersion}/${errorCode()}" + private fun Throwable.errorCode(hashedFields: (Throwable) -> Array = Throwable::defaultHashedFields): String { val hash = staticLocationBasedHash(hashedFields)