Add guarantees that PRESTO server constructors do not raise exceptions. (#66)

This commit is contained in:
Eugene Kabanov 2023-10-31 05:18:35 +02:00 committed by GitHub
parent a638b7a05b
commit 5ca16485e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -13,6 +13,8 @@ import stew/results
import route, common, segpath, servercommon, serverprivate, agent import route, common, segpath, servercommon, serverprivate, agent
export options, chronos, shttpserver, servercommon, chronicles, agent export options, chronos, shttpserver, servercommon, chronicles, agent
{.push raises: [].}
type type
SecureRestServer* = object of RootObj SecureRestServer* = object of RootObj
server*: SecureHttpServerRef server*: SecureHttpServerRef
@ -68,11 +70,11 @@ proc new*(t: typedesc[SecureRestServerRef],
else: else:
{.fatal: "Error type is not supported".} {.fatal: "Error type is not supported".}
proc localAddress*(rs: SecureRestServerRef): TransportAddress {.raises: [].} = proc localAddress*(rs: SecureRestServerRef): TransportAddress =
## Returns `rs` bound local socket address. ## Returns `rs` bound local socket address.
rs.server.instance.localAddress() rs.server.instance.localAddress()
proc state*(rs: SecureRestServerRef): RestServerState {.raises: [].} = proc state*(rs: SecureRestServerRef): RestServerState =
## Returns current REST server's state. ## Returns current REST server's state.
case rs.server.state case rs.server.state
of HttpServerState.ServerClosed: of HttpServerState.ServerClosed:

View File

@ -13,6 +13,8 @@ import stew/results
import route, common, segpath, servercommon, serverprivate, agent import route, common, segpath, servercommon, serverprivate, agent
export options, chronos, httpserver, servercommon, chronicles, agent export options, chronos, httpserver, servercommon, chronicles, agent
{.push raises: [].}
type type
RestServer* = object of RootObj RestServer* = object of RootObj
server*: HttpServerRef server*: HttpServerRef
@ -61,11 +63,11 @@ proc new*(t: typedesc[RestServerRef],
else: else:
{.fatal: "Error type is not supported".} {.fatal: "Error type is not supported".}
proc localAddress*(rs: RestServerRef): TransportAddress {.raises: [].} = proc localAddress*(rs: RestServerRef): TransportAddress =
## Returns `rs` bound local socket address. ## Returns `rs` bound local socket address.
rs.server.instance.localAddress() rs.server.instance.localAddress()
proc state*(rs: RestServerRef): RestServerState {.raises: [].} = proc state*(rs: RestServerRef): RestServerState =
## Returns current REST server's state. ## Returns current REST server's state.
case rs.server.state case rs.server.state
of HttpServerState.ServerClosed: of HttpServerState.ServerClosed: