CORDA-869: Clean up error reporting in node config/registration (#2268)

This commit is contained in:
Ross Nicoll 2017-12-18 16:54:48 +00:00 committed by GitHub
parent 21f0892deb
commit 22af527b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 28 deletions

View File

@ -1,5 +1,6 @@
package net.corda.node
import com.typesafe.config.ConfigException
import joptsimple.OptionParser
import joptsimple.util.EnumConverter
import net.corda.core.internal.div

View File

@ -39,7 +39,11 @@ open class NodeStartup(val args: Array<String>) {
*/
open fun run(): Boolean {
val startTime = System.currentTimeMillis()
assertCanNormalizeEmptyPath()
if (!canNormalizeEmptyPath()) {
println("You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version.")
println("Corda will now exit...")
return false
}
val (argsParser, cmdlineOptions) = parseArguments()
// We do the single node check before we initialise logging so that in case of a double-node start it
@ -92,6 +96,10 @@ open class NodeStartup(val args: Array<String>) {
return true
}
logStartupInfo(versionInfo, cmdlineOptions, conf)
} catch (e: Exception) {
logger.error("Exception during node registration", e)
return false
}
try {
cmdlineOptions.baseDirectory.createDirectories()
@ -108,9 +116,6 @@ open class NodeStartup(val args: Array<String>) {
logger.info("Node exiting successfully")
return true
} catch (e: Exception) {
return false
}
}
open protected fun preNetworkRegistration(conf: NodeConfiguration) = Unit
@ -186,14 +191,7 @@ open class NodeStartup(val args: Array<String>) {
NetworkRegistrationHelper(conf, HTTPNetworkRegistrationService(compatibilityZoneURL)).buildKeystore()
}
open protected fun loadConfigFile(cmdlineOptions: CmdLineOptions): NodeConfiguration {
try {
return cmdlineOptions.loadConfig()
} catch (configException: ConfigException) {
println("Unable to load the configuration file: ${configException.rootCause.message}")
throw configException
}
}
open protected fun loadConfigFile(cmdlineOptions: CmdLineOptions): NodeConfiguration = cmdlineOptions.loadConfig()
open protected fun banJavaSerialisation(conf: NodeConfiguration) {
SerialFilter.install(if (conf.notary?.bftSMaRt != null) ::bftSMaRtSerialFilter else ::defaultSerialFilter)
@ -285,12 +283,13 @@ open class NodeStartup(val args: Array<String>) {
return hostName
}
private fun assertCanNormalizeEmptyPath() {
private fun canNormalizeEmptyPath(): Boolean {
// Check we're not running a version of Java with a known bug: https://github.com/corda/corda/issues/83
try {
return try {
Paths.get("").normalize()
true
} catch (e: ArrayIndexOutOfBoundsException) {
Node.failStartUp("You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version.")
false
}
}