Skip to content

Commit

Permalink
adding raises defect across the codebase (#572)
Browse files Browse the repository at this point in the history
* adding raises defect across the codebase

* use unittest2

* add windows deps caching

* update mingw link

* die on failed peerinfo initialization

* use result.expect instead of get

* use expect more consistently and rework inits

* use expect more consistently

* throw on missing public key

* remove unused closure annotation

* merge master
  • Loading branch information
dryajov committed May 24, 2021
1 parent 95cd250 commit b2c5706
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
9 changes: 5 additions & 4 deletions libp2p/daemon/daemonapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,11 @@ proc getPeerInfo(pb: var ProtoBuffer): PeerInfo
while pb.getBytes(2, address) != -1:
if len(address) != 0:
var copyaddr = address
result.addresses.add(
MultiAddress
.init(copyaddr)
.expect("Expected valid multiaddr"))
let addrRes = MultiAddress.init(copyaddr)
if addrRes.isErr:
raise newException(DaemonLocalError, addrRes.error)

result.addresses.add(MultiAddress.init(copyaddr).get())
address.setLen(0)

proc identity*(api: DaemonAPI): Future[PeerInfo] {.async.} =
Expand Down
4 changes: 4 additions & 0 deletions libp2p/protocols/secure/secio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ method init(s: Secio) {.gcsafe.} =
s.codec = SecioCodec

proc newSecio*(rng: ref BrHmacDrbgContext, localPrivateKey: PrivateKey): Secio =
let pkRes = localPrivateKey.getKey()
if pkRes.isErr:
raise newException(Defect, "Can't fetch local private key")

result = Secio(
rng: rng,
localPrivateKey: localPrivateKey,
Expand Down
2 changes: 1 addition & 1 deletion libp2p/stream/lpstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ proc readLp*(s: LPStream, maxSize: int): Future[seq[byte]] {.async, gcsafe.} =
await s.readExactly(addr res[0], res.len)
return res

method write*(s: LPStream, msg: seq[byte]): Future[void] {.base, raises: [Defect].} =
method write*(s: LPStream, msg: seq[byte]): Future[void] {.base.} =
doAssert(false, "not implemented!")

proc writeLp*(s: LPStream, msg: openArray[byte]): Future[void] =
Expand Down
5 changes: 0 additions & 5 deletions libp2p/switch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ proc mount*[T: LPProtocol](s: Switch, proto: T, matcher: Matcher = nil)
{.gcsafe, raises: [Defect, LPError].} =

if isNil(proto.handler):
raise newException(LPError,
"Protocol has to define a `handle` method or proc")

if proto.codec.len == 0:
raise newException(LPError,
"Protocol has to define a `codec` string")

s.ms.addHandler(proto.codecs, proto, matcher)
Expand Down

0 comments on commit b2c5706

Please sign in to comment.