mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-09 09:03:10 +00:00
fix invalid raises annotations (#132)
* `raises` should not be used with async * callbacks returning futures should not raise
This commit is contained in:
parent
3a9b77146a
commit
b4bab89abd
@ -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 =
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user