From 47cc17719f4293bf80a22ebe28e3bfc54b2a59a1 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 8 Mar 2024 14:43:42 +0100 Subject: [PATCH] print warning when calling failed (#521) `failed` cannot return true for futures that don't forward exceptions --- chronos/internal/raisesfutures.nim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/chronos/internal/raisesfutures.nim b/chronos/internal/raisesfutures.nim index ed85c036..2e09a1db 100644 --- a/chronos/internal/raisesfutures.nim +++ b/chronos/internal/raisesfutures.nim @@ -2,6 +2,8 @@ import std/[macros, sequtils], ../futures +{.push raises: [].} + type InternalRaisesFuture*[T, E] = ref object of Future[T] ## Future with a tuple of possible exception types @@ -205,13 +207,20 @@ macro checkRaises*[T: CatchableError]( `warning` assert(`runtimeChecker`, `errorMsg`) -proc error*[T](future: InternalRaisesFuture[T, void]): ref CatchableError {. +func failed*[T](future: InternalRaisesFuture[T, void]): bool {.inline.} = + ## Determines whether ``future`` finished with an error. + static: + warning("No exceptions possible with this operation, `failed` always returns false") + + false + +func error*[T](future: InternalRaisesFuture[T, void]): ref CatchableError {. raises: [].} = static: warning("No exceptions possible with this operation, `error` always returns nil") nil -proc readError*[T](future: InternalRaisesFuture[T, void]): ref CatchableError {. +func readError*[T](future: InternalRaisesFuture[T, void]): ref CatchableError {. raises: [ValueError].} = static: warning("No exceptions possible with this operation, `readError` always raises")