From 922a760a09d46f380c6b934d61bb96d1a72e7d78 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 25 Apr 2017 15:15:08 +0200 Subject: [PATCH] Shell: more aggressive catch/rethrow of errors during command line parse. Avoids stack traces being dumped to the console when an unknown party name is provided. --- .../kotlin/net/corda/jackson/StringToMethodCallParser.kt | 9 +++++++-- .../java/net/corda/node/shell/StartShellCommand.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/jackson/src/main/kotlin/net/corda/jackson/StringToMethodCallParser.kt b/client/jackson/src/main/kotlin/net/corda/jackson/StringToMethodCallParser.kt index fe268e83f4..225bb9ec59 100644 --- a/client/jackson/src/main/kotlin/net/corda/jackson/StringToMethodCallParser.kt +++ b/client/jackson/src/main/kotlin/net/corda/jackson/StringToMethodCallParser.kt @@ -146,11 +146,12 @@ open class StringToMethodCallParser @JvmOverloads constructor( } } - open class UnparseableCallException(command: String) : Exception("Could not parse as a command: $command") { + open class UnparseableCallException(command: String, cause: Throwable? = null) : Exception("Could not parse as a command: $command", cause) { class UnknownMethod(val methodName: String) : UnparseableCallException("Unknown command name: $methodName") class MissingParameter(methodName: String, val paramName: String, command: String) : UnparseableCallException("Parameter $paramName missing from attempt to invoke $methodName in command: $command") class TooManyParameters(methodName: String, command: String) : UnparseableCallException("Too many parameters provided for $methodName: $command") class ReflectionDataMissing(methodName: String, argIndex: Int) : UnparseableCallException("Method $methodName missing parameter name at index $argIndex") + class FailedParse(e: Exception) : UnparseableCallException(e.message ?: e.toString(), e) } /** @@ -195,7 +196,11 @@ open class StringToMethodCallParser @JvmOverloads constructor( val inOrderParams: List = parameters.mapIndexed { _, param -> val (argName, argType) = param val entry = tree[argName] ?: throw UnparseableCallException.MissingParameter(methodNameHint, argName, args) - om.readValue(entry.traverse(om), argType) + try { + om.readValue(entry.traverse(om), argType) + } catch(e: Exception) { + throw UnparseableCallException.FailedParse(e) + } } if (log.isDebugEnabled) { inOrderParams.forEachIndexed { i, param -> diff --git a/node/src/main/java/net/corda/node/shell/StartShellCommand.java b/node/src/main/java/net/corda/node/shell/StartShellCommand.java index 972de7e78b..3ec2e8e2ee 100644 --- a/node/src/main/java/net/corda/node/shell/StartShellCommand.java +++ b/node/src/main/java/net/corda/node/shell/StartShellCommand.java @@ -1,6 +1,6 @@ package net.corda.node.shell; -// A simple forwarded to the "flow start" command, for easier typing. +// A simple forwarder to the "flow start" command, for easier typing. import org.crsh.cli.*;