From 89eec9958a12555f7f1d967f5be0348731e5e335 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 27 Oct 2021 21:18:58 -0400 Subject: [PATCH] problem: Proxy doesn't render internal exceptions to JSON RPC errors --- .../emeraldpay/dshackle/proxy/WriteRpcJson.kt | 3 --- .../dshackle/proxy/WriteRpcJsonSpec.groovy | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt index e7c6a691..c0ed6ee4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt @@ -63,9 +63,6 @@ open class WriteRpcJson { Mono.empty() } } - .onErrorContinue { t, _ -> - log.warn("Failed to convert to JSON", t) - } } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/WriteRpcJsonSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/WriteRpcJsonSpec.groovy index a4f1d13d..7ddf8f09 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/WriteRpcJsonSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/WriteRpcJsonSpec.groovy @@ -16,10 +16,8 @@ */ package io.emeraldpay.dshackle.proxy -import com.google.protobuf.ByteString -import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.rpc.NativeCall -import io.emeraldpay.dshackle.test.TestingCommons +import org.jetbrains.annotations.NotNull import reactor.core.publisher.Flux import spock.lang.Specification @@ -143,4 +141,27 @@ class WriteRpcJsonSpec extends Specification { act[1] == '{"jsonrpc":"2.0","id":11,"error":{"code":-32002,"message":"oops"}}' act[2] == '{"jsonrpc":"2.0","id":15,"result":{"hash": "0x2484f459dc"}}' } + + def "Write JSON RPC error on exception"() { + setup: + def writer = new WriteRpcJson() { + @Override + String toJson(@NotNull ProxyCall call, @NotNull NativeCall.CallResult response) { + throw new NativeCall.CallFailure(1, new IllegalStateException("TEST")) + } + } + + def call = new ProxyCall(ProxyCall.RpcType.SINGLE) + call.ids[1] = 10 + def data = [ + new NativeCall.CallResult(1, '"0x1"'.bytes, null), + ] + when: + def act = Flux.fromIterable(data) + .transform(writer.toJsons(call)) + .collectList() + .block(Duration.ofSeconds(1)) + then: + act[0] == '{"jsonrpc":"2.0","id":10,"error":{"code":-32003,"message":"TEST"}}' + } }