mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-2645 Do not remove exception information in dev mode (#5023)
`ExceptionSerialisingRpcOpsProxy` was removing information about the original exception in dev mode. This code has been removed. Although there is no check in `ExceptionSerialisingRpcOpsProxy` for dev mode (and also due to it being about serialising), `ExceptionMaskingRpcOpsProxy` will handle the removal of exception data in non dev mode (production mode).
This commit is contained in:
parent
1c89565175
commit
855d1323a4
@ -20,7 +20,6 @@ class CashExceptionSerialisationTest {
|
||||
val node = startNode(rpcUsers = listOf(User("mark", "dadada", setOf(all())))).getOrThrow()
|
||||
val action = { node.rpc.startFlow(CashExceptionSerialisationTest::CashExceptionThrowingFlow).returnValue.getOrThrow() }
|
||||
assertThatThrownBy(action).isInstanceOfSatisfying(CashException::class.java) { thrown ->
|
||||
assertThat(thrown).hasNoCause()
|
||||
assertThat(thrown.stackTrace).isEmpty()
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,34 @@ import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat
|
||||
import org.hibernate.exception.GenericJDBCException
|
||||
import org.junit.Test
|
||||
import java.sql.SQLException
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class RpcExceptionHandlingTest {
|
||||
private val user = User("mark", "dadada", setOf(Permissions.all()))
|
||||
private val users = listOf(user)
|
||||
|
||||
@Test
|
||||
fun `rpc client receive client-relevant exceptions regardless of devMode`() {
|
||||
fun `rpc client receives wrapped exceptions in devMode with no stacktraces`() {
|
||||
val params = NodeParameters(rpcUsers = users)
|
||||
val clientRelevantMessage = "This is for the players!"
|
||||
|
||||
fun NodeHandle.throwExceptionFromFlow() {
|
||||
rpc.startFlow(::ClientRelevantErrorFlow, clientRelevantMessage).returnValue.getOrThrow()
|
||||
}
|
||||
|
||||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
||||
val devModeNode = startNode(params, BOB_NAME).getOrThrow()
|
||||
assertThatThrownBy { devModeNode.throwExceptionFromFlow() }.isInstanceOfSatisfying(ClientRelevantException::class.java) { exception ->
|
||||
assertEquals((exception.cause as CordaRuntimeException).originalExceptionClassName, SQLException::class.qualifiedName)
|
||||
assertThat(exception.stackTrace).isEmpty()
|
||||
assertThat((exception.cause as CordaRuntimeException).stackTrace).isEmpty()
|
||||
assertThat(exception.message).isEqualTo(clientRelevantMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rpc client receives client-relevant message regardless of devMode`() {
|
||||
val params = NodeParameters(rpcUsers = users)
|
||||
val clientRelevantMessage = "This is for the players!"
|
||||
|
||||
@ -37,9 +58,6 @@ class RpcExceptionHandlingTest {
|
||||
|
||||
fun assertThatThrownExceptionIsReceivedUnwrapped(node: NodeHandle) {
|
||||
assertThatThrownBy { node.throwExceptionFromFlow() }.isInstanceOfSatisfying(ClientRelevantException::class.java) { exception ->
|
||||
|
||||
assertThat(exception).hasNoCause()
|
||||
assertThat(exception.stackTrace).isEmpty()
|
||||
assertThat(exception.message).isEqualTo(clientRelevantMessage)
|
||||
}
|
||||
}
|
||||
@ -53,6 +71,25 @@ class RpcExceptionHandlingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rpc client receives no specific information in non devMode`() {
|
||||
val params = NodeParameters(rpcUsers = users)
|
||||
val clientRelevantMessage = "This is for the players!"
|
||||
|
||||
fun NodeHandle.throwExceptionFromFlow() {
|
||||
rpc.startFlow(::ClientRelevantErrorFlow, clientRelevantMessage).returnValue.getOrThrow()
|
||||
}
|
||||
|
||||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
||||
val node = startNode(ALICE_NAME, devMode = false, parameters = params).getOrThrow()
|
||||
assertThatThrownBy { node.throwExceptionFromFlow() }.isInstanceOfSatisfying(ClientRelevantException::class.java) { exception ->
|
||||
assertThat(exception).hasNoCause()
|
||||
assertThat(exception.stackTrace).isEmpty()
|
||||
assertThat(exception.message).isEqualTo(clientRelevantMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `FlowException is received by the RPC client only if in devMode`() {
|
||||
val params = NodeParameters(rpcUsers = users)
|
||||
|
@ -84,11 +84,6 @@ internal class ExceptionSerialisingRpcOpsProxy(private val delegate: CordaRPCOps
|
||||
log(error)
|
||||
CordaRuntimeException(error.message, error)
|
||||
}
|
||||
|
||||
if (result is CordaThrowable) {
|
||||
result.stackTrace = arrayOf<StackTraceElement>()
|
||||
result.setCause(null)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user