From b4ba2ca4c1de2f4d5dca60d29f1d2a560775d604 Mon Sep 17 00:00:00 2001 From: Bartman250 Date: Tue, 9 Apr 2019 19:37:28 +0100 Subject: [PATCH] CORDA-2834 Clarify error message when base directory doesn't exist (#4992) * setting non existant base directory now yields suitable error message * corrections to missing base directory message and comments added for clarity * added check for valid base directory before node loggin and bootstrapping * removed uneeded import * quantum computer joke back by popular demand and not back at the same time --- .../net/corda/node/internal/NodeStartup.kt | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index 7b1af64b81..603bb8190f 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -76,6 +76,24 @@ open class NodeStartupCli : CordaCliWrapper("corda", "Runs a Corda Node") { override fun additionalSubCommands() = setOf(networkCacheCli, justGenerateNodeInfoCli, justGenerateRpcSslCertsCli, initialRegistrationCli, validateConfigurationCli) + override fun call(): Int { + if (!validateBaseDirectory()) { + return ExitCodes.FAILURE + } + return super.call() + } + + private fun validateBaseDirectory(): Boolean { + //Ensure that the base directory actually exists before initialising and the rest of the node. + val baseDirectory = cmdLineOptions.baseDirectory + + if (!baseDirectory.exists()) { + printError("Base directory $baseDirectory does not exist. Node will now shutdown") + return false + } + return true + } + override fun runProgram(): Int { return when { InitialRegistration.checkRegistrationMode(cmdLineOptions.baseDirectory) -> { @@ -146,8 +164,10 @@ open class NodeStartup : NodeStartupLogging { Node.printBasicNodeInfo(LOGS_CAN_BE_FOUND_IN_STRING, System.getProperty("log-path")) // Step 5. Load and validate node configuration. - val rawConfig = cmdLineOptions.rawConfiguration().doOnErrors(cmdLineOptions::logRawConfigurationErrors).optional ?: return ExitCodes.FAILURE - val configuration = cmdLineOptions.parseConfiguration(rawConfig).doIfValid { logRawConfig(rawConfig) }.doOnErrors(::logConfigurationErrors).optional ?: return ExitCodes.FAILURE + val rawConfig = cmdLineOptions.rawConfiguration().doOnErrors(cmdLineOptions::logRawConfigurationErrors).optional + ?: return ExitCodes.FAILURE + val configuration = cmdLineOptions.parseConfiguration(rawConfig).doIfValid { logRawConfig(rawConfig) }.doOnErrors(::logConfigurationErrors).optional + ?: return ExitCodes.FAILURE // Step 6. Check if we can access the certificates directory if (requireCertificates && !canReadCertificatesDirectory(configuration.certificatesDirectory, configuration.devMode)) return ExitCodes.FAILURE @@ -390,7 +410,8 @@ open class NodeStartup : NodeStartupLogging { "When I discovered my toaster wasn't\nwaterproof, I was shocked.", "Where do cryptographers go for\nentertainment? The security theatre.", "How did the Java programmer get rich?\nThey inherited a factory.", - "Why did the developer quit his job?\nHe didn't get ar-rays." + "Why did the developer quit his job?\nHe didn't get ar-rays.", + "Quantum computer jokes are both\n funny and not funny at the same time." ) if (Emoji.hasEmojiTerminal)