Skip to content

Commit

Permalink
[CORDA-2172]: Add link to error-codes-webapp in Corda. (corda#4224)
Browse files Browse the repository at this point in the history
  • Loading branch information
sollecitom authored Nov 13, 2018
1 parent f3b0998 commit aa0ccec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<out Any?> = Throwable::defaultHashedFields): String {

val hash = staticLocationBasedHash(hashedFields)
Expand Down

0 comments on commit aa0ccec

Please sign in to comment.