mirror of https://github.com/vacp2p/nim-libp2p.git
Minor tweaking in errors.nim in order to give priority to Defect
This commit is contained in:
parent
4c6a123d31
commit
d96372f820
|
@ -15,38 +15,42 @@ macro checkFutures*[T](futs: seq[Future[T]], exclude: untyped = []): untyped =
|
||||||
case nexclude
|
case nexclude
|
||||||
of 0:
|
of 0:
|
||||||
quote do:
|
quote do:
|
||||||
let pos = instantiationInfo()
|
|
||||||
for res in `futs`:
|
for res in `futs`:
|
||||||
if res.failed:
|
if res.failed:
|
||||||
let exc = res.readError()
|
let exc = res.readError()
|
||||||
# We still don't abort but warn
|
# We still don't abort but warn
|
||||||
warn "Something went wrong in a future",
|
warn "Something went wrong in a future", error=exc.name
|
||||||
error=exc.name, file=pos.filename, line=pos.line
|
|
||||||
else:
|
else:
|
||||||
quote do:
|
quote do:
|
||||||
let pos = instantiationInfo()
|
|
||||||
for res in `futs`:
|
for res in `futs`:
|
||||||
block check:
|
block check:
|
||||||
if res.failed:
|
if res.failed:
|
||||||
let exc = res.readError()
|
let exc = res.readError()
|
||||||
for i in 0..<`nexclude`:
|
for i in 0..<`nexclude`:
|
||||||
if exc of `exclude`[i]:
|
if exc of `exclude`[i]:
|
||||||
trace "Ignoring an error (no warning)",
|
trace "Ignoring an error (no warning)", error=exc.name
|
||||||
error=exc.name, file=pos.filename, line=pos.line
|
|
||||||
break check
|
break check
|
||||||
# We still don't abort but warn
|
# We still don't abort but warn
|
||||||
warn "Something went wrong in a future",
|
warn "Something went wrong in a future", error=exc.name
|
||||||
error=exc.name, file=pos.filename, line=pos.line
|
|
||||||
|
|
||||||
proc allFuturesThrowing*[T](args: varargs[Future[T]]): Future[void] =
|
proc allFuturesThrowing*[T](args: varargs[Future[T]]): Future[void] =
|
||||||
var futs: seq[Future[T]]
|
var futs: seq[Future[T]]
|
||||||
for fut in args:
|
for fut in args:
|
||||||
futs &= fut
|
futs &= fut
|
||||||
proc call() {.async.} =
|
proc call() {.async.} =
|
||||||
|
var first: ref Exception = nil
|
||||||
futs = await allFinished(futs)
|
futs = await allFinished(futs)
|
||||||
for fut in futs:
|
for fut in futs:
|
||||||
if fut.failed:
|
if fut.failed:
|
||||||
raise fut.readError()
|
let err = fut.readError()
|
||||||
|
if err of Defect:
|
||||||
|
raise err
|
||||||
|
else:
|
||||||
|
if isNil(first):
|
||||||
|
first = err
|
||||||
|
if not isNil(first):
|
||||||
|
raise first
|
||||||
|
|
||||||
return call()
|
return call()
|
||||||
|
|
||||||
template tryAndWarn*(msg: static[string]; body: untyped): untyped =
|
template tryAndWarn*(msg: static[string]; body: untyped): untyped =
|
||||||
|
|
Loading…
Reference in New Issue