Skip to content

Commit

Permalink
Adding error logs for failed libwaku operations (#3067)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Oct 1, 2024
1 parent 8b0884c commit d8e6a5c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ proc process*(
of RETRIEVE_MY_ENR:
return ok($(%*waku.node.enr.toURI()))

error "unsupported operation in DebugNodeRequest"
return err("unsupported operation in DebugNodeRequest")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import std/[json, sequtils]
import chronos, results, libp2p/multiaddress
import chronos, chronicles, results, libp2p/multiaddress
import
../../../../waku/factory/waku,
../../../../waku/discovery/waku_dnsdisc,
Expand Down Expand Up @@ -117,6 +117,7 @@ proc process*(
of START_DISCV5:
let res = await waku.wakuDiscv5.start()
res.isOkOr:
error "START_DISCV5 failed", error = error
return err($error)

return ok("discv5 started correctly")
Expand All @@ -126,17 +127,21 @@ proc process*(
return ok("discv5 stopped correctly")
of GET_BOOTSTRAP_NODES:
let nodes = retrieveBootstrapNodes($self[].enrTreeUrl, $self[].nameDnsServer).valueOr:
error "GET_BOOTSTRAP_NODES failed", error = error
return err($error)

return ok($(%*nodes))
of UPDATE_DISCV5_BOOTSTRAP_NODES:
updateDiscv5BootstrapNodes($self[].nodes, waku).isOkOr:
error "UPDATE_DISCV5_BOOTSTRAP_NODES failed", error = error
return err($error)

return ok("discovery request processed correctly")
of PEER_EXCHANGE:
let numValidPeers = (await performPeerExchangeRequestTo(self[].numPeers, waku)).valueOr:
error "PEER_EXCHANGE failed", error = error
return err("error calling performPeerExchangeRequestTo: " & $error)
return ok($numValidPeers)

error "discovery request not handled"
return err("discovery request not handled")
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ proc process*(
case self.operation
of CREATE_NODE:
waku[] = (await createWaku(self.configJson)).valueOr:
error "CREATE_NODE failed", error = error
return err("error processing createWaku request: " & $error)
of START_NODE:
(await waku.startWaku()).isOkOr:
error "START_NODE failed", error = error
return err("problem starting waku: " & $error)
of STOP_NODE:
try:
await waku[].stop()
except Exception:
error "STOP_NODE failed", error = getCurrentExceptionMsg()
return err("exception stopping node: " & getCurrentExceptionMsg())

return ok("")
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ proc process*(
of CONNECT_TO:
let ret = waku.node.connectTo($self[].peerMultiAddr, self[].dialTimeout)
if ret.isErr():
error "CONNECT_TO failed", error = ret.error
return err(ret.error)
of GET_ALL_PEER_IDS:
## returns a comma-separated string of peerIDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,22 @@ proc process*(
let pubsubTopic = $self.pubsubTopic

if waku.node.wakuLightpushClient.isNil():
return err("LightpushRequest waku.node.wakuLightpushClient is nil")
let errorMsg = "LightpushRequest waku.node.wakuLightpushClient is nil"
error "PUBLISH failed", error = errorMsg
return err(errorMsg)

let peerOpt = waku.node.peerManager.selectPeer(WakuLightPushCodec)
if peerOpt.isNone():
return err("failed to lightpublish message, no suitable remote peers")
let errorMsg = "failed to lightpublish message, no suitable remote peers"
error "PUBLISH failed", error = errorMsg
return err(errorMsg)

(
await waku.node.wakuLightpushClient.publish(
pubsubTopic, msg, peer = peerOpt.get()
)
).isOkOr:
error "PUBLISH failed", error = error
return err("LightpushRequest error publishing: " & $error)

return ok("")
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ proc process*(

let numPeers = await waku.node.wakuRelay.publish(pubsubTopic, msg)
if numPeers == 0:
return err("Message not sent because no peers found.")
let errorMsg = "Message not sent because no peers found."
error "PUBLISH failed", error = errorMsg
return err(errorMsg)
elif numPeers > 0:
let msgHash = computeMessageHash(pubSubTopic, msg).to0xHex
return ok(msgHash)
of LIST_CONNECTED_PEERS:
let numConnPeers = waku.node.wakuRelay.getNumConnectedPeers($self.pubsubTopic).valueOr:
error "LIST_CONNECTED_PEERS failed", error = error
return err($error)
return ok($numConnPeers)
of LIST_MESH_PEERS:
let numPeersInMesh = waku.node.wakuRelay.getNumPeersInMesh($self.pubsubTopic).valueOr:
error "LIST_MESH_PEERS failed", error = error
return err($error)
return ok($numPeersInMesh)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import std/[json, sugar, options]
import chronos, results
import chronos, chronicles, results
import
../../../../../waku/factory/waku,
../../../../alloc,
Expand Down Expand Up @@ -143,4 +143,5 @@ proc process*(
of REMOTE_QUERY:
return await cast[ptr JsonStoreQueryRequest](self[].storeReq).process(waku)

error "store request not handled at all"
return err("store request not handled at all")

0 comments on commit d8e6a5c

Please sign in to comment.