exception warning fixes (#403)

This commit is contained in:
Jacek Sieka 2023-06-05 13:03:38 +02:00 committed by GitHub
parent 157ca4fea5
commit a6ac5f2213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 24 deletions

View File

@ -395,7 +395,7 @@ proc futureContinue*(fut: FutureBase) {.raises: [Defect], gcsafe.} =
# Every call to an `{.async.}` proc is redirected to call this function # Every call to an `{.async.}` proc is redirected to call this function
# instead with its original body captured in `fut.closure`. # instead with its original body captured in `fut.closure`.
var next: FutureBase var next: FutureBase
try: template iterate =
while true: while true:
# Call closure to make progress on `fut` until it reaches `yield` (inside # Call closure to make progress on `fut` until it reaches `yield` (inside
# `await` typically) or completes / fails / is cancelled # `await` typically) or completes / fails / is cancelled
@ -417,6 +417,19 @@ proc futureContinue*(fut: FutureBase) {.raises: [Defect], gcsafe.} =
return return
# Continue while the yielded future is already finished. # Continue while the yielded future is already finished.
when chronosStrictException:
try:
iterate
except CancelledError:
fut.cancelAndSchedule()
except CatchableError as exc:
fut.fail(exc)
finally:
next = nil # GC hygiene
else:
try:
iterate
except CancelledError: except CancelledError:
fut.cancelAndSchedule() fut.cancelAndSchedule()
except CatchableError as exc: except CatchableError as exc:

View File

@ -1498,7 +1498,7 @@ proc wait*[T](fut: Future[T], timeout = -1): Future[T] {.
include asyncmacro2 include asyncmacro2
proc runForever*() {.raises: [Defect, CatchableError].} = proc runForever*() =
## Begins a never ending global dispatcher poll loop. ## Begins a never ending global dispatcher poll loop.
## Raises different exceptions depending on the platform. ## Raises different exceptions depending on the platform.
while true: while true:

View File

@ -408,7 +408,7 @@ proc init*(t: typedesc[IpNet], network: string): IpNet {.
if len(parts) > 1: if len(parts) > 1:
try: try:
prefix = parseInt(parts[1]) prefix = parseInt(parts[1])
except: except ValueError:
prefix = -1 prefix = -1
if prefix == -1: if prefix == -1:
ipaddr = parseIpAddress(parts[1]) ipaddr = parseIpAddress(parts[1])
@ -434,8 +434,8 @@ proc init*(t: typedesc[IpNet], network: string): IpNet {.
result = t.init(host, mask) result = t.init(host, mask)
else: else:
result = t.init(host, prefix) result = t.init(host, prefix)
except: except ValueError as exc:
raise newException(TransportAddressError, "Incorrect network address!") raise newException(TransportAddressError, exc.msg)
proc `==`*(n1, n2: IpNet): bool {.inline.} = proc `==`*(n1, n2: IpNet): bool {.inline.} =
## Returns ``true`` if networks ``n1`` and ``n2`` are equal in IP family and ## Returns ``true`` if networks ``n1`` and ``n2`` are equal in IP family and

View File

@ -463,7 +463,7 @@ suite "Datagram Transport test suite":
try: try:
await wait(dgram.join(), 1.seconds) await wait(dgram.join(), 1.seconds)
result = true result = true
except: except CatchableError:
discard discard
proc testBroadcast(): Future[int] {.async.} = proc testBroadcast(): Future[int] {.async.} =

View File

@ -913,9 +913,9 @@ suite "HTTP client testing suite":
await allFutures(f1, f2) await allFutures(f1, f2)
check: check:
f1.finished() f1.finished()
f1.done() f1.completed()
f2.finished() f2.finished()
f2.done() f2.completed()
f1.read() == (200, "ok", 0) f1.read() == (200, "ok", 0)
f2.read() == (200, "ok", 0) f2.read() == (200, "ok", 0)
session.connectionsCount == 2 session.connectionsCount == 2
@ -976,9 +976,9 @@ suite "HTTP client testing suite":
await allFutures(f1, f2) await allFutures(f1, f2)
check: check:
f1.finished() f1.finished()
f1.done() f1.completed()
f2.finished() f2.finished()
f2.done() f2.completed()
f1.read() == (200, "ok", 0) f1.read() == (200, "ok", 0)
f2.read() == (200, "ok", 0) f2.read() == (200, "ok", 0)
session.connectionsCount == 0 session.connectionsCount == 0

View File

@ -575,7 +575,7 @@ suite "Network utilities test suite":
try: try:
inet = IpNet.init(item[0]) inet = IpNet.init(item[0])
res = true res = true
except: except TransportAddressError:
res = false res = false
check: check:
$res == item[1] $res == item[1]

View File

@ -689,7 +689,7 @@ suite "Stream Transport test suite":
try: try:
await wait(server.join(), 10.seconds) await wait(server.join(), 10.seconds)
result = 1 result = 1
except: except CatchableError:
discard discard
proc testWriteConnReset(address: TransportAddress): Future[int] {.async.} = proc testWriteConnReset(address: TransportAddress): Future[int] {.async.} =
@ -765,7 +765,7 @@ suite "Stream Transport test suite":
try: try:
transp = await connect(address) transp = await connect(address)
flag = true flag = true
except: except CatchableError:
server.stop() server.stop()
server.close() server.close()
await server.join() await server.join()