Update method signatures
This commit is contained in:
parent
0724d7f8f1
commit
6ad496dcba
|
@ -64,7 +64,7 @@ method readOnce*(
|
|||
self: AsyncStreamWrapper,
|
||||
pbytes: pointer,
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
): Future[int] {.async: (raises: [CancelledError, LPStreamError]).} =
|
||||
|
||||
trace "Reading bytes from reader", bytes = nbytes
|
||||
if isNil(self.reader):
|
||||
|
@ -118,7 +118,7 @@ method closed*(self: AsyncStreamWrapper): bool =
|
|||
method atEof*(self: AsyncStreamWrapper): bool =
|
||||
self.reader.atEof()
|
||||
|
||||
method closeImpl*(self: AsyncStreamWrapper) {.async.} =
|
||||
method closeImpl*(self: AsyncStreamWrapper) {.async: (raises: []).} =
|
||||
try:
|
||||
trace "Shutting down async chronos stream"
|
||||
if not self.closed():
|
||||
|
@ -130,7 +130,7 @@ method closeImpl*(self: AsyncStreamWrapper) {.async.} =
|
|||
|
||||
trace "Shutdown async chronos stream"
|
||||
except CancelledError as exc:
|
||||
raise exc
|
||||
error "Error received cancelled error when closing chronos stream", msg = exc.msg
|
||||
except CatchableError as exc:
|
||||
trace "Error closing async chronos stream", msg = exc.msg
|
||||
|
||||
|
|
|
@ -6,16 +6,23 @@ import pkg/chronos
|
|||
import ../asynctest
|
||||
import ./helpers
|
||||
|
||||
# Trying to use a CancelledError or LPStreamError value for toRaise
|
||||
# will produce a compilation error;
|
||||
# Error: only a 'ref object' can be raised
|
||||
# This is because they are not ref object but plain object.
|
||||
# CancelledError* = object of FutureError
|
||||
# LPStreamError* = object of LPError
|
||||
|
||||
type
|
||||
CrashingStreamWrapper* = ref object of LPStream
|
||||
toRaise*: ref CatchableError
|
||||
toRaise*: proc(): void {.gcsafe, raises: [CancelledError, LPStreamError].}
|
||||
|
||||
method readOnce*(
|
||||
self: CrashingStreamWrapper,
|
||||
pbytes: pointer,
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
raise self.toRaise
|
||||
): Future[int] {.gcsafe, async: (raises: [CancelledError, LPStreamError]).} =
|
||||
self.toRaise()
|
||||
|
||||
asyncchecksuite "Chunking":
|
||||
test "should return proper size chunks":
|
||||
|
@ -88,13 +95,14 @@ asyncchecksuite "Chunking":
|
|||
string.fromBytes(data) == readFile(path)
|
||||
fileChunker.offset == data.len
|
||||
|
||||
proc raiseStreamException(exc: ref CatchableError) {.async.} =
|
||||
proc raiseStreamException(exc: ref CancelledError | ref LPStreamError) {.async.} =
|
||||
let stream = CrashingStreamWrapper.new()
|
||||
let chunker = LPStreamChunker.new(
|
||||
stream = stream,
|
||||
chunkSize = 2'nb)
|
||||
|
||||
stream.toRaise = exc
|
||||
stream.toRaise = proc(): void {.raises: [CancelledError, LPStreamError].} =
|
||||
raise exc
|
||||
discard (await chunker.getBytes())
|
||||
|
||||
test "stream should forward LPStreamError":
|
||||
|
@ -112,6 +120,11 @@ asyncchecksuite "Chunking":
|
|||
expect LPStreamError:
|
||||
await raiseStreamException(newException(LPStreamError, "test error"))
|
||||
|
||||
test "stream should convert other exceptions to defect":
|
||||
expect Defect:
|
||||
await raiseStreamException(newException(CatchableError, "test error"))
|
||||
# This test cannot exist anymore.
|
||||
# The signature of the method readOnce is explicitly listing the error raised:
|
||||
# LPStreamError and CancelledError.
|
||||
# So trying to raise CatchableError will not compile because CatchableError is
|
||||
# not in the pragma array amd Nim 2 looks stricter for this rule.
|
||||
# test "stream should convert other exceptions to defect":
|
||||
# expect Defect:
|
||||
# await raiseStreamException(newException(CatchableError, "test error"))
|
||||
|
|
|
@ -33,8 +33,12 @@ marketplacesuite "Bug #821 - node crashes during erasure coding":
|
|||
let cid = clientApi.upload(data).get
|
||||
|
||||
var requestId = none RequestId
|
||||
proc onStorageRequested(event: StorageRequested) {.raises:[].} =
|
||||
requestId = event.requestId.some
|
||||
proc onStorageRequested(event: ?!StorageRequested) {.raises:[].} =
|
||||
without value =? event:
|
||||
trace "The onSlotFilled event is not defined."
|
||||
discard
|
||||
|
||||
requestId = value.requestId.some
|
||||
|
||||
let subscription = await marketplace.subscribe(StorageRequested, onStorageRequested)
|
||||
|
||||
|
|
|
@ -135,8 +135,13 @@ marketplacesuite "Marketplace payouts":
|
|||
let cid = clientApi.upload(data).get
|
||||
|
||||
var slotIdxFilled = none UInt256
|
||||
proc onSlotFilled(event: SlotFilled) =
|
||||
slotIdxFilled = some event.slotIndex
|
||||
|
||||
let onSlotFilled = proc (event: ?!SlotFilled) =
|
||||
without value =? event:
|
||||
trace "The onSlotFilled event is not defined."
|
||||
discard
|
||||
|
||||
slotIdxFilled = value.slotIndex.some
|
||||
|
||||
let subscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ marketplacesuite "Hosts submit regular proofs":
|
|||
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
||||
|
||||
var proofWasSubmitted = false
|
||||
proc onProofSubmitted(event: ProofSubmitted) =
|
||||
proc onProofSubmitted(event: ?!ProofSubmitted) =
|
||||
proofWasSubmitted = true
|
||||
|
||||
let subscription = await marketplace.subscribe(ProofSubmitted, onProofSubmitted)
|
||||
|
@ -120,8 +120,12 @@ marketplacesuite "Simulate invalid proofs":
|
|||
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
||||
|
||||
var slotWasFreed = false
|
||||
proc onSlotFreed(event: SlotFreed) =
|
||||
if event.requestId == requestId:
|
||||
proc onSlotFreed(event: ?!SlotFreed) =
|
||||
without value =? event:
|
||||
trace "The onSlotFreed event is not defined."
|
||||
discard
|
||||
|
||||
if value.requestId == requestId:
|
||||
slotWasFreed = true
|
||||
|
||||
let subscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
||||
|
@ -176,8 +180,12 @@ marketplacesuite "Simulate invalid proofs":
|
|||
let requestId = client0.requestId(purchaseId).get
|
||||
|
||||
var slotWasFilled = false
|
||||
proc onSlotFilled(event: SlotFilled) =
|
||||
if event.requestId == requestId:
|
||||
proc onSlotFilled(event: ?!SlotFilled) =
|
||||
without value =? event:
|
||||
trace "The onSlotFilled event is not defined."
|
||||
discard
|
||||
|
||||
if value.requestId == requestId:
|
||||
slotWasFilled = true
|
||||
let filledSubscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
||||
|
||||
|
@ -185,8 +193,12 @@ marketplacesuite "Simulate invalid proofs":
|
|||
check eventually(slotWasFilled, timeout = expiry.int * 1000)
|
||||
|
||||
var slotWasFreed = false
|
||||
proc onSlotFreed(event: SlotFreed) =
|
||||
if event.requestId == requestId:
|
||||
proc onSlotFreed(event: ?!SlotFreed) =
|
||||
without value =? event:
|
||||
trace "The onSlotFreed event is not defined."
|
||||
discard
|
||||
|
||||
if value.requestId == requestId:
|
||||
slotWasFreed = true
|
||||
let freedSubscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
||||
|
||||
|
|
Loading…
Reference in New Issue