mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
CORDA-2632 Handle exceptions when file does not exist. (#4967)
* corda-2632 Added catch clause to handle argument exceptions and display the proper error. * Created specific exception for when the file is missing instead of the general catch all exception. * Changes according to code review.
This commit is contained in:
parent
7a7c471ebf
commit
4f382a65a3
@ -127,7 +127,7 @@ open class StringToMethodCallParser<in T : Any> @JvmOverloads constructor(
|
||||
return method.parameters.mapIndexed { index, param ->
|
||||
when {
|
||||
param.isNamePresent -> param.name
|
||||
// index + 1 because the first Kotlin reflection param is 'this', but that doesn't match Java reflection.
|
||||
// index + 1 because the first Kotlin reflection param is 'this', but that doesn't match Java reflection.
|
||||
kf != null -> kf.parameters[index + 1].name ?: throw UnparseableCallException.ReflectionDataMissing(method.name, index)
|
||||
else -> throw UnparseableCallException.ReflectionDataMissing(method.name, index)
|
||||
}
|
||||
@ -153,6 +153,7 @@ open class StringToMethodCallParser<in T : Any> @JvmOverloads constructor(
|
||||
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 NoSuchFile(filename: String) : UnparseableCallException("File $filename not found")
|
||||
class FailedParse(e: Exception) : UnparseableCallException(e.message ?: e.toString(), e)
|
||||
}
|
||||
|
||||
@ -212,6 +213,8 @@ open class StringToMethodCallParser<in T : Any> @JvmOverloads constructor(
|
||||
val entryType = om.typeFactory.constructType(argType)
|
||||
try {
|
||||
om.readValue<Any>(entry.traverse(om), entryType)
|
||||
} catch (e: java.nio.file.NoSuchFileException) {
|
||||
throw UnparseableCallException.NoSuchFile(e.file ?: entry.toString())
|
||||
} catch (e: Exception) {
|
||||
throw UnparseableCallException.FailedParse(e)
|
||||
}
|
||||
|
@ -527,7 +527,9 @@ object InteractiveShell {
|
||||
}
|
||||
} catch (e: StringToMethodCallParser.UnparseableCallException) {
|
||||
out.println(e.message, Color.red)
|
||||
out.println("Please try 'man run' to learn what syntax is acceptable")
|
||||
if (e !is StringToMethodCallParser.UnparseableCallException.NoSuchFile) {
|
||||
out.println("Please try 'man run' to learn what syntax is acceptable")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
out.println("RPC failed: ${e.rootCause}", Color.red)
|
||||
} finally {
|
||||
|
Loading…
Reference in New Issue
Block a user