Add more raises in async pragma

This commit is contained in:
Arnaud 2025-02-25 13:43:49 +01:00 committed by Giuliano Mega
parent 9586f95ccd
commit 92f9533c7d
5 changed files with 20 additions and 15 deletions

View File

@ -189,7 +189,7 @@ method query*(
var
iter = QueryIter.new()
proc next(): Future[?!QueryResponse] {.async.} =
proc next(): Future[?!QueryResponse] {.async: (raises: [CancelledError]).} =
let
path = walker()
@ -208,8 +208,13 @@ method query*(
key = Key.init(keyPath).expect("should not fail")
data =
if query.value:
self.readFile((basePath / path).absolutePath)
.expect("Should read file")
try:
self.readFile((basePath / path).absolutePath)
.expect("Should read file")
except ValueError as err:
return failure err
except OSError as err:
return failure err
else:
@[]

View File

@ -98,7 +98,7 @@ method query*(
limit = query.limit
)
proc next(): Future[?!QueryResponse] {.async.} =
proc next(): Future[?!QueryResponse] {.async: (raises: [CancelledError]).} =
if iter.finished:
return failure(newException(QueryEndedError, "Calling next on a finished query!"))
@ -114,7 +114,7 @@ method query*(
except LevelDbException as e:
return failure("LevelDbDatastore.query -> next exception: " & $e.msg)
proc dispose(): Future[?!void] {.async.} =
proc dispose(): Future[?!void] {.async: (raises: [CancelledError]).} =
dbIter.dispose()
return success()

View File

@ -23,8 +23,8 @@ type
QueryResponse* = tuple[key: ?Key, data: seq[byte]]
QueryEndedError* = object of DatastoreError
GetNext* = proc(): Future[?!QueryResponse] {.raises: [], gcsafe, closure.}
IterDispose* = proc(): Future[?!void] {.raises: [], gcsafe.}
GetNext* = proc(): Future[?!QueryResponse] {.async: (raises: [CancelledError]), gcsafe, closure.}
IterDispose* = proc(): Future[?!void] {.async: (raises: [CancelledError]), gcsafe.}
QueryIter* = ref object
finished*: bool
next*: GetNext
@ -34,7 +34,7 @@ iterator items*(q: QueryIter): Future[?!QueryResponse] =
while not q.finished:
yield q.next()
proc defaultDispose(): Future[?!void] {.gcsafe, async.} =
proc defaultDispose(): Future[?!void] {.gcsafe, async: (raises: [CancelledError]).} =
return success()
proc new*(T: type QueryIter, dispose = defaultDispose): T =

View File

@ -267,7 +267,7 @@ method query*(
if not (v == SQLITE_OK):
return failure newException(DatastoreError, $sqlite3_errstr(v))
proc next(): Future[?!QueryResponse] {.async.} =
proc next(): Future[?!QueryResponse] {.async: (raises: [CancelledError]).} =
if iter.finished:
return failure(newException(QueryEndedError, "Calling next on a finished query!"))
@ -321,7 +321,7 @@ method query*(
iter.finished = true
return failure newException(DatastoreError, $sqlite3_errstr(v))
iter.dispose = proc(): Future[?!void] {.async.} =
iter.dispose = proc(): Future[?!void] {.async: (raises: [CancelledError]).} =
discard sqlite3_reset(s)
discard sqlite3_clear_bindings(s)
iter.next = nil

View File

@ -47,11 +47,11 @@ type
TypedDatastore* = ref object of RootObj
ds*: Datastore
Modify*[T] = proc(v: ?T): Future[?T] {.raises: [CatchableError], gcsafe, closure.}
ModifyGet*[T, U] = proc(v: ?T): Future[(?T, U)] {.raises: [CatchableError], gcsafe, closure.}
Modify*[T] = proc(v: ?T): Future[?T] {.raises: [CancelledError], gcsafe, closure.}
ModifyGet*[T, U] = proc(v: ?T): Future[(?T, U)] {.raises: [CancelledError], gcsafe, closure.}
QueryResponse*[T] = tuple[key: ?Key, value: ?!T]
GetNext*[T] = proc(): Future[?!QueryResponse[T]] {.raises: [], gcsafe, closure.}
GetNext*[T] = proc(): Future[?!QueryResponse[T]] {.async: (raises: [CancelledError]), gcsafe, closure.}
QueryIter*[T] = ref object
finished*: bool
next*: GetNext[T]
@ -161,14 +161,14 @@ proc query*[T](self: TypedDatastore, q: Query): Future[?!QueryIter[T]] {.async:
return failure(childErr)
var iter = QueryIter[T]()
iter.dispose = proc (): Future[?!void] {.async.} =
iter.dispose = proc (): Future[?!void] {.async: (raises: [CancelledError]).} =
await dsIter.dispose()
if dsIter.finished:
iter.finished = true
return success(iter)
proc getNext: Future[?!QueryResponse[T]] {.async.} =
proc getNext: Future[?!QueryResponse[T]] {.async: (raises: [CancelledError]).} =
without pair =? await dsIter.next(), error:
return failure(error)