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
# instead with its original body captured in `fut.closure`.
var next: FutureBase
try:
template iterate =
while true:
# Call closure to make progress on `fut` until it reaches `yield` (inside
# `await` typically) or completes / fails / is cancelled
@ -417,17 +417,30 @@ proc futureContinue*(fut: FutureBase) {.raises: [Defect], gcsafe.} =
return
# Continue while the yielded future is already finished.
except CancelledError:
fut.cancelAndSchedule()
except CatchableError as exc:
fut.fail(exc)
except Exception as exc:
if exc of Defect:
raise (ref Defect)(exc)
fut.fail((ref ValueError)(msg: exc.msg, parent: exc))
finally:
next = nil # GC hygiene
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:
fut.cancelAndSchedule()
except CatchableError as exc:
fut.fail(exc)
except Exception as exc:
if exc of Defect:
raise (ref Defect)(exc)
fut.fail((ref ValueError)(msg: exc.msg, parent: exc))
finally:
next = nil # GC hygiene
# `futureContinue` will not be called any more for this future so we can
# clean it up

View File

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

View File

@ -408,7 +408,7 @@ proc init*(t: typedesc[IpNet], network: string): IpNet {.
if len(parts) > 1:
try:
prefix = parseInt(parts[1])
except:
except ValueError:
prefix = -1
if prefix == -1:
ipaddr = parseIpAddress(parts[1])
@ -434,8 +434,8 @@ proc init*(t: typedesc[IpNet], network: string): IpNet {.
result = t.init(host, mask)
else:
result = t.init(host, prefix)
except:
raise newException(TransportAddressError, "Incorrect network address!")
except ValueError as exc:
raise newException(TransportAddressError, exc.msg)
proc `==`*(n1, n2: IpNet): bool {.inline.} =
## 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:
await wait(dgram.join(), 1.seconds)
result = true
except:
except CatchableError:
discard
proc testBroadcast(): Future[int] {.async.} =

View File

@ -913,9 +913,9 @@ suite "HTTP client testing suite":
await allFutures(f1, f2)
check:
f1.finished()
f1.done()
f1.completed()
f2.finished()
f2.done()
f2.completed()
f1.read() == (200, "ok", 0)
f2.read() == (200, "ok", 0)
session.connectionsCount == 2
@ -976,9 +976,9 @@ suite "HTTP client testing suite":
await allFutures(f1, f2)
check:
f1.finished()
f1.done()
f1.completed()
f2.finished()
f2.done()
f2.completed()
f1.read() == (200, "ok", 0)
f2.read() == (200, "ok", 0)
session.connectionsCount == 0
@ -1261,7 +1261,7 @@ suite "HTTP client testing suite":
test "HTTP client no-pipeline test":
let address = initTAddress("127.0.0.1:30080")
check waitFor(testNoPipeline(address)) == true
test "HTTP client server-sent events test":
let address = initTAddress("127.0.0.1:30080")
check waitFor(testServerSentEvents(address, false)) == true

View File

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

View File

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