checked exceptions in stores

This commit is contained in:
Marcin Czenko 2025-03-29 11:11:29 +01:00
parent 414906a070
commit 5abce8107c
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
2 changed files with 6 additions and 8 deletions

View File

@ -161,7 +161,7 @@ proc retrieveCid(
proc retrieveInfoHash(
node: CodexNodeRef, infoHash: MultiHash, resp: HttpResponseRef
): Future[void] {.async.} =
): Future[void] {.async: (raises: [CancelledError, HttpWriteError]).} =
## Download torrent from the node in a streaming
## manner
##
@ -194,13 +194,13 @@ proc retrieveInfoHash(
await resp.prepare(HttpResponseStreamType.Plain)
without torrentDownloader =?
node.getTorrentDownloader(torrentManifest, codexManifest), err:
without downloader =? node.getTorrentDownloader(torrentManifest, codexManifest), err:
error "Unable to stream torrent", err = err.msg
resp.status = Http500
await resp.sendBody(err.msg)
return
torrentDownloader = downloader
torrentDownloader.start()
while not torrentDownloader.finished:
@ -219,11 +219,6 @@ proc retrieveInfoHash(
except CancelledError as exc:
info "Stream cancelled", exc = exc.msg
raise exc
except CatchableError as exc:
warn "Error streaming blocks", exc = exc.msg
resp.status = Http500
if resp.isPending():
await resp.sendBody(exc.msg)
finally:
info "Sent bytes for torrent", infoHash = $infoHash, bytes
await torrentDownloader.stop()

View File

@ -157,6 +157,9 @@ method listBlocks*(
without cid =? cid, err:
trace "Cannot get Cid from the iterator", err = err.msg
return false
without isTorrent =? cid.isTorrentInfoHash, err:
trace "Error checking if cid is a torrent info hash", err = err.msg
return false
without isManifest =? cid.isManifest, err:
trace "Error checking if cid is a manifest", err = err.msg
return false