From 5abce8107c185556413a3e23f7e8d285a356d091 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Sat, 29 Mar 2025 11:11:29 +0100 Subject: [PATCH] checked exceptions in stores --- codex/rest/api.nim | 11 +++-------- codex/stores/cachestore.nim | 3 +++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 0be3a455..01c21f9b 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -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() diff --git a/codex/stores/cachestore.nim b/codex/stores/cachestore.nim index f3a72c9a..0b1876a1 100644 --- a/codex/stores/cachestore.nim +++ b/codex/stores/cachestore.nim @@ -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