fix invalid raises annotations (#132)

* `raises` should not be used with async
* callbacks returning futures should not raise
This commit is contained in:
Jacek Sieka 2022-03-21 15:19:49 +01:00 committed by GitHub
parent 3a9b77146a
commit b4bab89abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 11 deletions

View File

@ -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 =

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -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]