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.

This commit is contained in:
Mike Hearn 2017-04-25 15:15:08 +02:00 committed by Chris Rankin
parent 2a62496145
commit f894730693
2 changed files with 8 additions and 3 deletions

View File

@ -146,11 +146,12 @@ open class StringToMethodCallParser<in T : Any> @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<in T : Any> @JvmOverloads constructor(
val inOrderParams: List<Any?> = 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 ->

View File

@ -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.*;