From b4bab89abdde3653939abe36ab9f6cae4aa1cbd1 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 21 Mar 2022 15:19:49 +0100 Subject: [PATCH] fix invalid raises annotations (#132) * `raises` should not be used with async * callbacks returning futures should not raise --- json_rpc/client.nim | 6 +++--- json_rpc/clients/httpclient.nim | 7 ++++--- json_rpc/clients/socketclient.nim | 5 +++-- json_rpc/clients/websocketclient.nim | 6 ++++-- json_rpc/router.nim | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/json_rpc/client.nim b/json_rpc/client.nim index a1c27be..575a5fd 100644 --- a/json_rpc/client.nim +++ b/json_rpc/client.nim @@ -19,7 +19,7 @@ type Response* = JsonNode - GetJsonRpcRequestHeaders* = proc(): seq[(string, string)] {.gcsafe.} + GetJsonRpcRequestHeaders* = proc(): seq[(string, string)] {.gcsafe, raises: [Defect].} proc getNextId*(client: RpcClient): ClientId = client.lastId += 1 @@ -30,11 +30,11 @@ proc rpcCallNode*(path: string, params: JsonNode, id: ClientId): JsonNode = method call*(client: RpcClient, name: string, params: JsonNode): Future[Response] {. - base, async, gcsafe, raises: [Defect, CatchableError].} = + base, async, gcsafe, raises: [Defect].} = discard method close*(client: RpcClient): Future[void] {. - base, async, gcsafe, raises: [Defect, CatchableError].} = + base, async, gcsafe, raises: [Defect].} = discard template `or`(a: JsonNode, b: typed): JsonNode = diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index e18f0d1..2fe916c 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -8,6 +8,8 @@ import export client +{.push raises: [Defect].} + logScope: topics = "JSONRPC-HTTP-CLIENT" @@ -48,7 +50,7 @@ proc newRpcHttpClient*( method call*(client: RpcHttpClient, name: string, params: JsonNode): Future[Response] - {.async, gcsafe, raises: [Defect, CatchableError].} = + {.async, gcsafe.} = doAssert client.httpSession != nil if client.httpAddress.isErr: raise newException(RpcAddressUnresolvableError, client.httpAddress.error) @@ -114,8 +116,7 @@ method call*(client: RpcHttpClient, name: string, # TODO: Provide more clarity regarding the failure here raise newException(InvalidResponse, "Invalid response") -proc connect*(client: RpcHttpClient, url: string) - {.async, raises: [Defect].} = +proc connect*(client: RpcHttpClient, url: string) {.async.} = client.httpAddress = client.httpSession.getAddress(url) if client.httpAddress.isErr: raise newException(RpcAddressUnresolvableError, client.httpAddress.error) diff --git a/json_rpc/clients/socketclient.nim b/json_rpc/clients/socketclient.nim index 54b1a7a..77dc643 100644 --- a/json_rpc/clients/socketclient.nim +++ b/json_rpc/clients/socketclient.nim @@ -3,6 +3,8 @@ import chronos, ../client +{.push raises: [Defect].} + export client type @@ -21,8 +23,7 @@ proc newRpcSocketClient*: RpcSocketClient = RpcSocketClient.new() method call*(self: RpcSocketClient, name: string, - params: JsonNode): Future[Response] {. - async, gcsafe, raises: [Defect, CatchableError].} = + params: JsonNode): Future[Response] {.async, gcsafe.} = ## Remotely calls the specified RPC method. let id = self.getNextId() var value = $rpcCallNode(name, params, id) & "\r\n" diff --git a/json_rpc/clients/websocketclient.nim b/json_rpc/clients/websocketclient.nim index ddbe374..34539cf 100644 --- a/json_rpc/clients/websocketclient.nim +++ b/json_rpc/clients/websocketclient.nim @@ -6,6 +6,9 @@ import export client +# TODO needs fixes in news +# {.push raises: [Defect].} + logScope: topics = "JSONRPC-WS-CLIENT" @@ -41,8 +44,7 @@ proc newRpcWebSocketClient*( RpcWebSocketClient.new(getHeaders) method call*(self: RpcWebSocketClient, name: string, - params: JsonNode): Future[Response] {. - async, gcsafe, raises: [Defect, CatchableError].} = + params: JsonNode): Future[Response] {.async, gcsafe.} = ## Remotely calls the specified RPC method. let id = self.getNextId() var value = $rpcCallNode(name, params, id) & "\r\n" diff --git a/json_rpc/router.nim b/json_rpc/router.nim index 09bb990..fc699cf 100644 --- a/json_rpc/router.nim +++ b/json_rpc/router.nim @@ -10,7 +10,7 @@ type StringOfJson* = JsonString # Procedure signature accepted as an RPC call by server - RpcProc* = proc(input: JsonNode): Future[StringOfJson] {.gcsafe, raises: [Defect, CatchableError].} + RpcProc* = proc(input: JsonNode): Future[StringOfJson] {.gcsafe, raises: [Defect].} RpcRouter* = object procs*: Table[string, RpcProc]