diff --git a/json_rpc/private/server_handler_wrapper.nim b/json_rpc/private/server_handler_wrapper.nim index 8c60d39..e7f2bb2 100644 --- a/json_rpc/private/server_handler_wrapper.nim +++ b/json_rpc/private/server_handler_wrapper.nim @@ -41,7 +41,7 @@ template rpc_isOptional[T](_: options.Option[T]): bool = true # Run time helpers # ------------------------------------------------------------------------------ -proc unpackArg(args: JsonString, argName: string, argType: type): argType +func unpackArg(args: JsonString, argName: string, argType: type): argType {.gcsafe, raises: [JsonRpcError].} = ## This where input parameters are decoded from JSON into ## Nim data types @@ -89,8 +89,16 @@ template expectOptionalParamsLen(params: RequestParamsRx, template expectParamsLen(params: RequestParamsRx, length: static[int]) = ## Make sure positional params meets the handler expectation + + # https://github.com/nim-lang/Nim/issues/24228 especially in a Chronos async + # context, with `{.compileTime.}` `$` `int`, `uint64`, and `int64` overloads + # https://github.com/nim-lang/Nim/blob/v2.0.10/lib/system/dollars.nim#L28-L34 + # provides for for compile-time evaluation from, can cause JSON-RPC code not + # to compile. Explicitly choose the non-CTFE overloads, which do not trigger + # this Nim issue. let - expected = "Expected " & $length & " Json parameter(s) but got " + nonConstLength = length + expected = "Expected " & $nonConstLength & " JSON parameter(s) but got " if params.positional.len != length: raise newException(RequestDecodeError, @@ -141,11 +149,11 @@ template unpackPositional(params: RequestParamsRx, else: # mandatory args # A and C fall into this category - # unpack Nim type and assign from json + # unpack Nim type and assign from JSON if params.notNull(pos): innerNode() -proc makeType(typeName, params: NimNode): NimNode = +func makeType(typeName, params: NimNode): NimNode = ## Generate type section contains an object definition ## with fields of handler params let typeSec = quote do: @@ -159,14 +167,14 @@ proc makeType(typeName, params: NimNode): NimNode = obj[2] = recList typeSec -proc makeParams(retType: NimNode, params: NimNode): seq[NimNode] = +func makeParams(retType: NimNode, params: NimNode): seq[NimNode] = ## Convert rpc params into handler params result.add retType if params.len > 1: for i in 1..