diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 37d20514..805f40c2 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -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 diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index 8c9b6261..cb95d8f7 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -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: diff --git a/chronos/transports/ipnet.nim b/chronos/transports/ipnet.nim index 1d61cb6d..130e8fa0 100644 --- a/chronos/transports/ipnet.nim +++ b/chronos/transports/ipnet.nim @@ -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 diff --git a/tests/testdatagram.nim b/tests/testdatagram.nim index 1eea4895..17385a3f 100644 --- a/tests/testdatagram.nim +++ b/tests/testdatagram.nim @@ -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.} = diff --git a/tests/testhttpclient.nim b/tests/testhttpclient.nim index 07128d9d..16f00171 100644 --- a/tests/testhttpclient.nim +++ b/tests/testhttpclient.nim @@ -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 diff --git a/tests/testnet.nim b/tests/testnet.nim index 419195d8..c6355d4c 100644 --- a/tests/testnet.nim +++ b/tests/testnet.nim @@ -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] diff --git a/tests/teststream.nim b/tests/teststream.nim index 416e0a9c..7601a397 100644 --- a/tests/teststream.nim +++ b/tests/teststream.nim @@ -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()